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

查看:24
本文介绍了未保存 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天全站免登陆