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

Aam*_*imi -3 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
Run Code Online (Sandbox Code Playgroud)

谁能告诉我哪个是准确的,请简要说明一下?

JCo*_*ode 5

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

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

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

  • 鉴于这是一个面试问题,答案很可能是 #3,即旧的“phpsessid” URL 参数,这是我们在浏览器广泛支持 cookie 之前必须使用的参数。类似于Java的`jsessionid` (2认同)