doudiao2335 2014-06-14 13:19
浏览 43
已采纳

session_destroy()+ session_start()不在标题重定向之后

Trying to temporary store information in a multipage sign up. Because I don't want old sessions to mess with the new sign up data I'm trying to destroy the old session. The problem is the following.

Not working:

signup1.php

//Start new session
session_regenerate_id(TRUE);
session_destroy();
unset($_SESSION);
session_start();

//Store values in session
$_SESSION['created']    = time(); 

//Redirect to second step
header('Location: '.$settings->siteurl.'signup2.php');
exit();

signup2.php

<pre>
<?php 
    //Print $_SESSION (empty array)
    print_r($_SESSION); 
?>

Working (but returns old $_SESSION values + updated values):

//Start new session
session_regenerate_id(TRUE);

//Store values in session
$_SESSION['created']    = time(); 

//Redirect to second step
header('Location: '.$settings->siteurl.'signup2.php');
exit();

What could resolve the problem? First session_start(); is set in init.php but it doesn't matter if I place it above session_regenerate_id(TRUE), array stays empty.

  • 写回答

1条回答 默认 最新

  • dongyangzhi0687 2014-06-14 13:37
    关注

    You should use this first:

    session_start(); // Starts a new or resumes an existing session
    

    Then you may use:

    session_regenerate_id(TRUE); // regenerates the active session id
    

    The TRUE/delete_old_session parameter is used for:

    Whether to delete the old associated session file or not.

    The session_regenerate_id is useful to prevent session hijacking and it just regenerates a new id but keeps session data. This should be used when user's access level changes or using a time interval (i.e. after every 10 minutes) but before you regenerate another new session id you need to start the session first.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog