重定向而不更改浏览器网址

编程入门 行业动态 更新时间:2024-10-23 17:24:04
本文介绍了重定向而不更改浏览器网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下网址

www.example/home.php and www.example/login.php

无论何时我从php重定向到这些页面中的任何一个,浏览器的URL都应保留为www.example.

When ever I redirect to anyof these pages from php , the url of the browser should remain www.example.

我已经尝试过,但是由于对mod_rewite的了解不足,我无法做任何事情.

I have tried,but I could not do anything due to lack of knowledge in mod_rewite.

请帮助,在此先感谢

推荐答案

如果要在登录后将页面保留为用户未登录时的相同URL(我们假设为www.example),这很容易:

If you want to keep the page after login, to the same URL when the user was not login (we assume www.example), that's easy:

在www.example中,它会加载index.php,因此我们应该更改index.php的内容.

in www.example it loads the index.php, so we should change index.php's content.

当未登录的用户第一次访问它时,它具有以下内容:

It has this content when the user who is not logged in, first visit it:

include("htmls/index.html"); // index.html could contain whatever you like

但是您添加了这个条件,上面的行在一个条件内:

But you add this condition, the above line is inside a condition:

if(isset($_POST['form-submit'])) { // do the login process and if success include("htmls/index_loggedin.html"); } else if(is_user_logged_in()===true) { include("htmls/index_loggedin.html"); // } else { include("htmls/index.html"); // means the user has not submitted anything and is also not logged in }

上面的代码表明,如果用户已登录,请处理其登录信息,然后添加 用于已登录用户的视图(如果用户已经登录过)也将向他/她显示用于已登录用户的视图,否则,如果未登录用户也未发送登录请求,则向他显示未登录用户的基本视图.我假设您表单的提交"按钮名为表单提交".

The above code says that if the user has logged in, process his/her login and then include a view which is for logged in users, also if the user is already logged, also shows him/her the view which is for logged in users, otherwise, if the user is not logged, nor has sent no request of loggin in, then show him a basic view for unlogged users. I have assumed the submit button of your form is named "form-submit".

但是,上面的命名只是为了清楚起见.例如,您可以将index.html和index_loggedin.html合并为一个view_index.php,然后将主index.php的条件也复制到view_index.php.

However the above naming is just for sake of clarity. For instance, you can combine index.html and index_loggedin.html into one view_index.php and then also duplicate the conditions of the main index.php to also the view_index.php.

最后一点是,您应该将代码和视图尽可能地分开.

A last note is that, you should separate the code and the view as fully as possible.

更多推荐

重定向而不更改浏览器网址

本文发布于:2023-10-31 12:56:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546150.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   重定向   浏览器   网址

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!