简体   繁体   中英

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.

I don't know the idea of doing that.

I know that Facebook does it. (Logging in, and logged in page url is same but different page)

I'm using nginx, PHP.

Should I some sort of rewrite URL? or some configuration on nginx? Or should I manipulate header with php in some way? 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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