会话:让Page2.php在刷新时显示404错误

会话:让Page2.php在刷新时显示404错误

问题描述:

I'm trying to set the session with Page1.php, redirect to Page2.php, and then if Page2.php is refreshed, closed, revisited i want it to display a 404 error. This is what I have:

page1.php:

session_start();
$_SESSION['time'] = 'time';
header('location: page2.php');
exit;

page2.php:

session_start();

if( !isset( $_SESSION['time'] ) ) {
    header("Location:http://google.com");
} else {
    echo ( "this session is ". $_SESSION['time'] );
}

How do I add the function so page2.php expires if refreshed? I just want the page2.php url to expire for the user after the browser session ends

我正在尝试使用Page1.php设置会话,重定向到Page2.php,然后再设置Page2。 php刷新,关闭,重新访问我希望它显示404错误。 这就是我所拥有的: p>

page1.php: p>

  session_start(); 
 $ _SESSION ['time'] ='  time'; 
header('location:page2.php'); 
exit; 
  code>  pre> 
 
 

page2.php: p>

   session_start(); 
 
if(!isset($ _SESSION ['time'])){
 header(“Location:http://google.com”); 
} else {
 echo  (“此会话是”。$ _SESSION ['time']); 
} 
  code>  pre> 
 
 

如何添加该功能以便page2.php在刷新后到期? 我只是想在浏览器会话结束后为用户过期page2.php网址 p> div>

if you want to expire the session, do that with session_destroy()

and finally call

header("HTTP/1.0 404 Not Found");

In a nutshell, once you start a session with session_start(); you will be able to access the session variables stored in $_SESSION.

And when you are done with the session, call the session_destroy() to clean up and kill the session.

for eg:

if($action =='logout') {
    session_destroy();
}

PS: if you have set session.auto_start in your php.ini configuration, you dont have to call session_start() at the top of the page.

For more information on session_destroy, follow this link: http://php.net/manual/en/function.session-destroy.php

For full details on session: http://php.net/manual/en/ref.session.php

add

$_SESSION['time'] = '';

at the end of else