douqiang4501 2013-03-21 01:27
浏览 103

会话超时和自动重定向

When a user clicks on a link and they get to the next page, it starts a session which long story short, tells the database to make that link unavailable. They only have 30 minutes to do what they are supposed to do on this page, before the database resets making the link available again.. How can I make it so that the user cannot sit and stay on the page keeping the link unavailable or clicking refresh to stay on same page?

So basically, is there a way I can automatically redirect the user to another page WITHOUT them clicking on anything? The page should redirect them to another page when session expires no matter what.

I dont think I can use this because I want the redirect dependent on when the session expires.

header("Refresh: 60; Location: /path/somepage.php");

Any help would be extremely helpful!

** EDIT, the 30 minutes is defined in the session. So its all about the session..

$now = time();

$_SESSION['start'] = time(); // taking now page start time
$_SESSION['expire'] = $_SESSION['start'] + (1 * 60) ; // ending a session in 30

$outOfTime = $_SESSION['expire'] - $_SESSION['start'];

if($now > $_SESSION['expire'])
{

    header("Refresh: $outOfTime ; Location: /path/redirect.php");

}

Session timer set to 1 minute for testing purposes.

  • 写回答

3条回答 默认 最新

  • 普通网友 2013-03-21 01:43
    关注

    You should have a system that checks how much longer until the session expires that runs whenever the user enters a page and set the redirect to that long. For example:

    <?php
    #some code to get expiration date of session. Make sure it is in a datetime object.
    #get difference between current time and expiration time:
    $timeleft=$expirationTime-new DateTime('now');
    header("Refresh: {$timeleft};Location: http://example.com");
    ?>
    

    I am not good with date/time, so you may have to fix this the code, but the concept is the main intention of this answer.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大