douyin7416 2012-10-03 17:49
浏览 11
已采纳

确保PHP会话安全

When an user creates an account, he is given an user id from the database that is unique and auto-incremented. So the first user has the user id of 1, the second user created has the user id of 2, and so on. I'm using PHP sessions to store the user id when they are signed in so that they stayed signed in. After reading several articles, I get the point that you never want PHP sessions to be as vulnerable as I have made it (It's easy for a hacker to determine what the php session user id is of each user. So my question is, If I was to use md5 or blowfish based on their unique username to generate an user id for each user, will that make PHP sessions secure?

  • 写回答

1条回答 默认 最新

  • dongnianchou7047 2012-10-03 17:51
    关注

    A good approach would always be to at the login screen and immediately post login to force a new session id generated using random numbers

    session_start();
    $newsessid = somerandomnumberfunction();
    session_id($newsessid);
    

    you can also use session_regenerate_id() function to generate a new id

    session_start();
    session_regenerate_id();
    

    Good Read

    PHP Session Security

    PHP Security Guide: Sessions

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

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现