PHP会话数据未保存 [英] PHP Session data not being saved

查看:55
本文介绍了PHP会话数据未保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一种我发誓我没碰服务器"的情况.老实说,我没有碰过任何PHP脚本.我遇到的问题是php数据没有保存在不同的页面或页面刷新中.我知道一个新的会话正在正确创建,因为我可以设置一个会话变量(例如$ _SESSION ['foo'] ="foo"并将其打印回同一页就可以了.但是当我尝试使用相同的变量时在另一页上未设置!是否可以在主机服务器上使用任何php函数或信息以查看发生了什么情况?

I have one of those "I swear I didn't touch the server" situations. I honestly didn't touch any of the php scripts. The problem I am having is that php data is not being saved across different pages or page refreshes. I know a new session is being created correctly because I can set a session variable (e.g. $_SESSION['foo'] = "foo" and print it back out on the same page just fine. But when I try to use that same variable on another page it is not set! Is there any php functions or information I can use on my hosts server to see what is going on?

这是一个示例脚本,目前无法在我的主机的服务器上运行:

Here is an example script that does not work on my hosts' server as of right now:

<?php
session_start();
if(isset($_SESSION['views']))
    $_SESSION['views'] = $_SESSION['views']+ 1;
else
    $_SESSION['views'] = 1;

echo "views = ". $_SESSION['views'];
echo '<p><a href="page1.php">Refresh</a></p>';
?>

刷新页面后,"views"变量永远不会增加.我认为这对他们来说是个问题,但我想确保我不是一个完全的白痴.

The 'views' variable never gets incremented after doing a page refresh. I'm thinking this is a problem on their side, but I wanted to make sure I'm not a complete idiot first.

这是主机服务器(PHP版本4.4.7)的phpinfo():

Here is the phpinfo() for my hosts' server (PHP Version 4.4.7):

推荐答案

感谢所有有用的信息.事实证明,我的主机更改了服务器并开始使用/var/php_sessions以外的其他会话保存路径,该路径不再存在.一种解决方案是在我所有的脚本文件中声明ini_set(' session.save_path','SOME WRITABLE PATH');,但这将是一件很痛苦的事情.我与主机进行了交谈,他们明确地将会话路径设置为确实存在的真实路径.希望这对遇到会话路径问题的人有所帮助.

Thanks for all the helpful info. It turns out that my host changed servers and started using a different session save path other than /var/php_sessions which didn't exist anymore. A solution would have been to declare ini_set(' session.save_path','SOME WRITABLE PATH'); in all my script files but that would have been a pain. I talked with the host and they explicitly set the session path to a real path that did exist. Hope this helps anyone having session path troubles.

这篇关于PHP会话数据未保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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