PHP会话ID在每个请求上都会更改 [英] PHP Session ID changing on every request
问题描述
我刚刚将我的应用程序从本地WAMP迁移到了实际的在线服务器.这造成了会话ID无法保存的麻烦.
- 我已经检查了session_start之前是否输出了不需要的字符
- 我似乎找不到在/tmp中保存的任何会话文件
这些是我的会话设置:
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /tmp /tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies On On
session.use_trans_sid 0 0
- 在线服务器正在运行:PHP版本5.3.9,而WAMP是:PHP版本5.3.5.
- 通过查看发送的标题和每个页面加载中的响应,我得到以下信息,set-cookie发送适当的会话ID,而收到的响应则发送一个新的会话ID,就像什么都没请求一样.
- 我正在预览URL(启用SSL)上运行网站.我不知道这是否有关系,我的域名尚未注册.
-
错误代码很简单:
$sId = session_id();
if ($sId == '') { session_start(); }
我刚刚解决了完全相同的问题.
事实证明,已发送cookie PHPSESSID(用于记录会话记录),但服务器已将其忽略,因此每次页面重新加载或更改时,会话均未维护且服务器重新启动了会话. /p>
问题是我在wp-config.php中有这行:
@ini_set('session.cookie_secure','On');
这意味着如果连接不安全,则将忽略每个cookie,因此服务器将重新启动PHPSESSID cookie和会话.
检查您的 wp-config.php 或您的 init.php . Cookie有问题.
I have just migrated my application from a local WAMP to the actual online server. This has caused trouble with the session ID not being saved as it appears.
- I have checked for unwanted characters being outputted before session_start
- I can't seem to find any session file being saved in my /tmp
These are my session settings:
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /tmp /tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies On On
session.use_trans_sid 0 0
- The online server is running: PHP Version 5.3.9 while the WAMP is: PHP Version 5.3.5.
- By viewing the headers sent and the response in every page load I got the following, the set-cookie sends the appropriate session id and the response received sends a new one as if nothing was requested.
- I am running the site on a preview URL (SSL on). I don't know if this has anything to do, my domain is not registered yet.
Error code is as simple as:
$sId = session_id();
if ($sId == '') { session_start(); }
I just had and solved the exact same problem.
It turns out that the cookie PHPSESSID (that keeps record of the session) was been send but it was ignored by the server, so the session was not maintained and the server restarted the session every time the page reloads or changes.
The problem was that I had in my wp-config.php this line:
@ini_set('session.cookie_secure','On');
This means that if the connection is not secure, every cookies is to be ignored, therefore the server the PHPSESSID cookie and the session was restarted.
Check your wp-config.php or your init.php. Is a problem with cookies.
这篇关于PHP会话ID在每个请求上都会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!