首页 > 解决方案 > 如果浏览器不支持 cookie,PHP 如何维护会话?

问题描述

今天我在采访中被问到

如果浏览器不支持 cookie,PHP 如何维护会话?

选项是....

1. using an MD5 hash of the user's email address as the session identifier


2. using the browser's network address as the session identifier


3. including the session identifier as a parameter every GET and POST request


4. using the "secure cookie" header to force the browser to set a cookie

谁能告诉我哪个是准确的,请给出一个简短的解释?

标签: php

解决方案


正如我们在评论中讨论的那样 - 2 个答案有意义,2 个没有意义。

  1. 完全依赖于会话,所以它不起作用。
  2. 会工作,但同一网络中的人将共享相同的会话。
  3. 是另一种会话可以工作的方式,但是如果您共享 url,则会发生与 2nd 相同的错误。
  4. 一个明显的诱饵答案。

建议的答案是 2 和 3 组合(如果只能选择一个,则为 3),在 URL 中存储由带有 unix 时间戳的 IP 地址标识的会话,以区分用户。


推荐阅读