PHP 会话变量不写入文件 [英] PHP session variables not writing to files
问题描述
我的 PHP 会话正在创建,但 $_SESSION
变量没有写入会话文件.
My PHP sessions are being created but $_SESSION
variables are not being written to the session file.
我在这里使用了三个测试 PHP 页面来诊断此问题:
I have three test PHP pages here that I'm using to diagnose this problem:
test_a.html
:
<html>
<body>
<form action='test_b.php' method='post'>
Put something here:
<input type='text' name='saveme' />
<input type='submit' value='Go!' />
</form>
</body>
</html>
test_b.php
:
<?php
session_start();
$_SESSION['saveme']=$_POST['saveme'];
echo "Here's what you wrote:<br>".$_SESSION['saveme']."<br>".
"<a href='test_c.php'>Take me to the final check</a><br>";
echo "And here's your session_id: ".session_id();
session_write_close();
?>
test_c.php
:
<?php
session_start();
echo "Here's what you wrote (maybe?):<br>".$_SESSION['saveme']."<br>".
"You should also see saveme below:<br>";
foreach ($_SESSION as $key=>$val)
echo $key." ".$val."<br>";
echo "And here's your session_id: ".session_id();
?>
当打开 test_a.html
并在文本框中输入任何内容并点击 Go! 时,它将正确显示在 test_b.php
上(当它被设置和调用时从内存中)但它没有显示在 test_c.php
上.
When opening test_a.html
and typing in anything to the textbox and hitting Go!, it will show up correctly on test_b.php
(when it is set and recalled from memory) but it is not shown on test_c.php
.
session_id
已设置并显示相同.cookie 已正确存储.会话文件在文件系统中正确创建,但未写入并保持零字节文件.
The session_id
is set and shows to be the same. The cookie is stored correctly. The session file is created correctly in the filesystem, but is not written to and remains a zero-byte file.
现在我网站的任何页面上都没有写入会话(尽管到目前为止已经运行了一年多),因此这些代码片段(如果有)中的错别字可能无关紧要.
Sessions are now not being written on any pages of my site (despite working for well over a year up to this point) so typos in these code snippets (if any) are likely irrelevant.
我检查过的东西:
- 会话存储目录是可写的,磁盘有足够的存储空间
session_start
总是成功的(之前什么都没有)session_id
已正确创建并且在两个页面上都相同- 会话 cookie 是使用正确的
session_id
创建的 session.use_cookies
和session.use_only_cookies
已开启- 注册全局变量已关闭
- Cookie 已启用
- 清除了
/tmp
目录以减少文件系统问题的可能性 - 尝试将会话数据存储在内存中(无效)
- 尝试更改会话文件位置(无效)
- 在 Chrome & 上测试火狐
- The session storage directory is writeable and the disk has plenty of storage
session_start
is always successful (and there is nothing before it)- The
session_id
is created correctly and is the same on both pages - The session cookie is created with the correct
session_id
session.use_cookies
andsession.use_only_cookies
are on- Register globals is off
- Cookies are enabled
- Cleared the
/tmp
directory to reduce possibility of filesystem issues - Tried storing the session data in memory (didn't work)
- Tried changing the session file location (didn't work)
- Tested on Chrome & Firefox
想法?
推荐答案
PHP 会话键用竖线分隔 |所以|键名会破坏你的会话.也许这就是问题所在.
PHP session keys are separated by the pipe character | so | in key name will break you session. Maybe this is the problem.
检查一下:
这篇关于PHP 会话变量不写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!