重定向而不更改浏览器网址 [英] Redirect without changing the browser url

查看:127
本文介绍了重定向而不更改浏览器网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网址

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

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

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

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

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

请帮助,在此先感谢

推荐答案

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

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

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

in www.example.com 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.

这篇关于重定向而不更改浏览器网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆