donglu9898 2016-08-06 00:05
浏览 39
已采纳

在设置安全值之后或之前重新生成会话ID

This is a very specific question regarding when exactly to call session_regenerate_id(). Is there a difference or security risk between calling session_regenerate_id() before or after setting a secure value in session.

Before setting a value:

if ($login_success) {

    session_regenerate_id(true);
    $_SESSION['login_status'] = 'logged_in';

}

Or after setting a value in session:

if ($login_success) {

    $_SESSION['login_status'] = 'logged_in';
    session_regenerate_id(true);

}
  • 写回答

2条回答 默认 最新

  • dongle7637 2016-08-06 00:39
    关注

    This is how it works, session_regenerate_id() will create and change the session id, transferring the session to the new file and send out the cookie. Passing true as an argument will also delete the old session file, omitting the argument will leave it.

    So, whether you use

    session_regenerate_id(true);
    $_SESSION['login_status'] = 'logged_in';
    

    or

    $_SESSION['login_status'] = 'logged_in';
    session_regenerate_id(true);
    

    it is the same: info is rewritten to the new file and the cookie is sent out. I'd advise using true as argument though at all times, to avoid old session hijacking.

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

报告相同问题?

悬赏问题

  • ¥15 关于#单片机#的问题:Lora通讯模块hc-14电路图求内部原理图
  • ¥50 esp32 wroom 32e 芯片解锁
  • ¥15 bywave配置文件写入失败
  • ¥20 基于Simulink的ZPW2000轨道电路仿真
  • ¥15 pycharm找不到在环境装好的opencv-python
  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥15 Mabatis查询数据