且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

没有会话的PHP用户身份验证教程

更新时间:2022-05-24 21:17:01

您基本上可以实现像您这样的会话.

You could basically implement something session like yourself.

这将包括以下任务:

  • 为新用户生成一个随机会话ID(或在登录时-根据确切使用情况...)
  • 将其保存到cookie
  • 将其他会话信息与会话ID(例如在数据库表中)一起保存在服务器上的某处
  • 在随后的页面访问中,检查cookie中的会话ID和网络服务器上的数据,以识别用户并授予访问权限

但是应该提到的是,基于cookie的解决方案从来没有那么好.例如,如果一个客户端没有启用cookie,那么它将根本无法使用.一个可能的解决方案是,如果未启用cookie,则将会话ID作为GET参数与每个内部链接一起发送.

However it should be mentioned that a cookie only based solution is never that good. If a client for example doesn't have cookies enabled it won't work at all. A possible solution for this is to send the session id as GET parameter with every internal link if cookies are not enabled.