doulaozhi6835 2015-01-24 15:25
浏览 16
已采纳

会话:让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

  • 写回答

2条回答 默认 最新

  • drug95107 2015-01-24 15:28
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现