0

My session variables are resetting every time I load a new page.

I have included a header.php file to each script with the session_start() function at the very top like so:

session_start();
error_reporting(E_ERROR);

I have also checked to make sure that the session_id is the same across all pages and it is.

I checked my web host's php_ini config file and I saw that the session.save_path was set to /tmp. I changed it to /var/lib/session/ like someone had suggested on this site and I began to get odd warnings in my code.

Warning: session_start() [function.session-start]: open(/var/lib/php/session//sess_97fca6d21c7ffa8333cd42eaa87f2eac, O_RDWR) failed: Permission denied (13) in /home/mforsyth/public_html/Beesting/header.php on line 2

I do not know what to do to fix this problem. Any help would be useful. If more details are needed please let me know.

EDIT: I have changed the folder back to /tmp and have made sure i can read/write into it and I can. I have also echoed the session id on every page and it all comes out the same. Also it seems that the session only lasts for one page

4

4 回答 4

2

发生的事情是 php 尝试使用它写入 ThinkingMonkey 提到的目录的一些信息来跟踪您的会话。

由于 php/webserver 进程的用户无法写入该目录,因此失败。因此,您没有获得会话。

找出进程在哪个用户下运行,并授予他对该目录的读/写权限。

于 2012-07-19T21:56:24.187 回答
1

谢谢您的帮助。在进一步调查并与我的主人讨论此事后,我能够得出结论,问题不在于写入 /tmp 文件夹的能力。实际上问题出在我的 header.php 包含文件中的一个 javascript 函数。

function logout()
{
    <?
session_destroy();
?>
alert("you have been logged out");
}

它避免了它在函数中的事实,这可能是我看到两种语言的编译方式不同的错。我做了一个简单的 ajax 调用来处理会话销毁,现在一切都很好。我想知道那里是否还有其他人有类似的问题,这是否对他们有帮助。

于 2012-07-20T20:35:38.313 回答
0

尝试重启webserver和php服务,如果是nginx/php-fpm,试试

root@server > service nginx restart
root@server > service php-fpm restart

这应该够了吧!

于 2015-05-20T09:25:37.940 回答
0

有同样的一般问题,结果出于某种原因我使用 JavaScript 来删除会话 cookie。

document.cookie = '[session_name]' +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
于 2015-10-07T20:47:18.913 回答