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 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题