如何在登出功能中将会话ID标记为过时

时间:2016-03-13 18:24:33

标签: php security session login

有人建议this website为了实现强大的注销功能,您必须将会话ID标记为过时。

我想知道你到底会怎么做?我已经包含session_regenerate_id(true),但我不确定这是否会将会话ID标记为过时。

当提交索引页面上的注销表单时,它们将被发送回登录页面:

登录页面:

if(isset($_POST["log_out"]) && ($_POST["log_out"] == '1')) {
    //this means we have come from another page after pressing the log out button 
    //so therefore we remove session variables and destroy session

    //The logout function on your website should mark session IDs as obsolete.
    session_regenerate_id(true); //is this right????????

    session_unset(); 
    session_destroy(); 
    $loginMessage = "You have been logged out";
}

索引页面注销表单:

<form id="form-log-out" name="form-log-out" method="post" action="login.php" onsubmit="return confirmLogOut()">
    <input name="log_out" type="hidden" value="1"/>
    <input type="submit" class="button_style" value="Log Out" />
</form>

1 个答案:

答案 0 :(得分:1)

根据the docssession_regenerate_id

  

使用新生成的

更新[s]当前会话ID      

...

     

session_regenerate_id()会将当前会话ID替换为新会话ID,并保留当前会话信息。

因此,是的,这会使旧的会话ID过时。

有关详细信息,请参阅this question