简体   繁体   English

同一会话的不同内容?

[英]different content for the same session?

I have 2 php pages in the same domain. 我在同一个域中有2个php页面。 One is in the root, other one is 3 folder below. 一个在根目录下,另一个在3个文件夹下。 A also have the following code in both files: A在两个文件中也都包含以下代码:

[...]
session_start();
var_dump(array('id' => session_id(), 'name' => session_name(), 'content' => $_SESSION));
die();
[...]

id is the same, name is the same, content differs... id相同, name相同, content不同...

If I execute session_regenerate_id() in any of them, both pages will have the new session id, but content still differs. 如果我在其中任何一个中执行session_regenerate_id() ,则两个页面都将具有新的会话ID,但是content仍然不同。 Cleaning up browser cache and wiping out all existing cookies won't help. 清理浏览器缓存并清除所有现有的Cookie将无济于事。

what have I missed? 我错过了什么?

All kinds of session settings can differ per-dir. 每个目录的所有会话设置都可能不同。 Note that these can be set in php configuration, host configuration, per-dir configuration (in apache: .htaccess), but also in code . 请注意,这些可以在php配置,主机配置,每个目录配置(在Apache:.htaccess中)中设置, 也可以在代码中设置

To determine what differs, inspecting the output of ini_get_all('session') at the point in the code you use the session probably shows the difference in settings. 为了确定差异,在使用会话的代码中检查ini_get_all('session')的输出可能会显示出设置的差异。

With the described symptoms (session id is the same for the different dirs, but the stored content varies), the most likely reasons are that either save_handler is different (another mechanism is used to store the session, eg files vs. memcached), or save_path is different (another location is used for storing the sessions). 使用上述症状(不同目录的会话ID相同,但存储的内容不同),最可能的原因是save_handler不同(使用另一种机制来存储会话,例如文件vs. memcached),或save_path是不同的(另一个位置用于存储会话)。 In this case it was the save_path according to the comments. 在这种情况下,根据注释是save_path

Note that if the session-id is different in the 2 directories, the most likely cause is an incorrect cookie_path setting, if it differs between subdomains, look at the cookie_domain setting. 请注意,如果两个目录中的session-id 不同 ,则最可能的原因是cookie_path设置不正确;如果子域之间的cookie_path设置不同,请查看cookie_domain设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM