dongzhan1383 2014-08-13 19:11
浏览 8
已采纳

在PHP中维护用户登录的建议?

That is, once the login credentials are checked and verified, what happens next so that on subsequent page loads (and page visits from other already logged-in sessions) the visitor is securely confirmed to be valid and logged in?

Should one use a mix of $_COOKIE and $_SESSION? What specifically is stored in either so as to be secure?

Do you confirm both or just one (if so, which) against the DB on each page load?

The best guides I can find are at 8 and 10 years old:

http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice

http://jaspan.com/improved_persistent_login_cookie_best_practice

surely there is something more current that I am just unable to find?

Any guidance would be supremely appreciated.

Thanks kindly

  • 写回答

1条回答 默认 最新

  • dpdhnd3577 2014-08-13 19:23
    关注

    The most common way to keep track of whether or not a user is logged in is to use a session variable, and check that the session variable is set at the beginning of each script that only should be accessed by users that have previously logged in.

    Having said that, there are a number of potential vulnerabilities that you should be aware of (such as session hijacking attacks and cross-site scripting attacks), and you should code accordingly to make sure that you site is not vulnerably to these types of attacks. For instance, the cookies used to keep track of the session should be sent over https only, and should not be accessible to client-side scripts. Regenerating the session every time the users privileges are elevated, to prevent session fixation, is also a good measure.

    The article below also has some good information: http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL

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

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害