简体   繁体   English

如何在不使用PHP更改URL的情况下重定向页面?

[英]How can I redirect page without changing URL with PHP?

I want the following: 我想要以下内容:

After logging in, A user will have assigned session variable, and the logging in page will be refreshed. 登录后,将为用户分配会话变量,并且刷新登录页面。 The URL should not be changed at all but the page would be different. 完全不应更改URL,但页面会有所不同。

I don't know the idea of doing that. 我不知道这样做的想法。

I know that Facebook does it. 我知道Facebook做到了。 (Logging in, and logged in page url is same but different page) (登录和登录的页面URL相同,但页面不同)

I'm using nginx, PHP. 我正在使用nginx,PHP。

Should I some sort of rewrite URL? 我应该重写网址吗? or some configuration on nginx? 或nginx上的某些配置? Or should I manipulate header with php in some way? 还是应该以某种方式用php处理标头? then how to? 那怎么办?

just do a conditional on an include. 只是对包含条件做一个条件。 In general if the session does not exist you say something like 通常,如果会话不存在,您会说类似

<?
if (!isset($_SESSION['user'])){ include_once("login_please.php"); exit(); }

..actual page content

?>

Use PHP to decide what to show (or which page to include) based on the session variable. 使用PHP根据会话变量决定要显示的内容(或要包含的页面)。

if ($_SESSION['form_submitted'] == true) {
    include('content.php');
}
else include('form.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM