PHP 会话变量在每次页面加载时重置 [英] PHP Session variables resetting with each page load

查看:36
本文介绍了PHP 会话变量在每次页面加载时重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次加载新页面时,我的会话变量都会重置.

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

我已经在每个脚本中包含了一个 header.php 文件,并在最顶部使用 session_start() 函数,如下所示:

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);

我还进行了检查以确保 session_id 在所有页面中都相同,并且确实如此.

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

我检查了我的网络主机的 php_ini 配置文件,我看到 session.save_path 被设置为 /tmp.我把它改成 /var/lib/session/ 就像有人在这个网站上建议的那样,我开始在我的代码中收到奇怪的警告.

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.

警告: session_start() [function.session-start]: open(/var/lib/php/session//sess_97fca6d21c7ffa8333cd42eaa87f2eac, O_RDWR) 失败: 中的权限被拒绝 (13)/home/mforsyth/public_html/Beesting/header.php 在线 2

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.

我已将文件夹改回/tmp 并确保我可以读/写它并且我可以.我还在每个页面上回显了会话 ID,结果都是一样的.似乎会话只持续一页

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

推荐答案

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

What happens is that php tries to track your sessions with some information it writes to the directory that ThinkingMonkey mentioned.

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

As the directory is not writable by the php/webserver process' user, this fails. Thus you don't get a session.

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

Find out which user the process is running under and grant him the read/write right for that directory.

这篇关于PHP 会话变量在每次页面加载时重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆