未维护 PHP 会话变量 [英] PHP session variables not being maintaned

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

问题描述

我有一个使用会话变量的应用程序,没问题.我在使用 when 的每个页面上的标题之前启动会话,它一直很好然后似乎突然我在导航到设置会话变量的页面以外的页面时收到未定义的索引错误.但仅限于某些浏览器.有时会维护会话,有时则不会.

I have an application that has been working with session variables no problem. I start the session before the headers on every page that uses when, it has been fine then it seems all of a sudden I'm getting an undefined index error when I navigate to a page other than the one that sets up the session variables. But only on some browsers. Sometimes sessions are maintained and sometimes they aren't.

似乎有时不会存储 cookie.我使用不同的浏览器进行了检查,有时会存储 cookie,有时不会.

It seems that cookies aren't being stored some of the time. I've done checks using different browsers and sometimes cookies are stored and sometimes not.

我做了一个实验.我正在使用 Firefox 来使用应用程序,并且我一直在关注存储会话的 tmp 文件夹.我把它清理干净了.使用 firefox 我开始使用该应用程序,使用会话正在使用的所有页面,最后我检查了 tmp 文件夹,其中有一个会话文件.

I did an experiment. I was using firefox to use to app and I was keeping an eye on the tmp folder where the sessions are stored. I cleaned it out. Using firefox I started using the app, using all the pages that sessions were in use and at the end I checked the tmp folder and it had one session file in there.

与 Internet Explorer 完全相同,现在有 7 个不同的会话文件.

Did the exact same with internet explorer and there are now 7 different session files.

我将 PHP 5.3.0 与 WAMP 堆栈一起使用.阿帕奇 2.2.11.在我的 phpinfo() 中启用了会话支持.

I'm using PHP 5.3.0 with the WAMP stack. Apache 2.2.11. Session support is enabled in my phpinfo().

我在第一页调用 var dump 并打印出会话数据.在任何后续页面上,会话变量为空.

I call a var dump on the first page and it prints out the session data. On any subsequent pages the session variable is empty.

<?php var_dump($_SESSION); ?>

array(0){}

谁能帮我想办法解决这个问题?

Can anyone help me figure out a solution to this?

更新 - PHP INI 会话设置

Directive        Local Value     Master Value
session.auto_start Off           Off 
session.bug_compat_42 On         On 
session.bug_compat_warn On       On 
session.cache_expire 180         180 
session.cache_limiter nocache    nocache 
session.cookie_domain 82.68.26.169   82.68.26.169 
session.cookie_httponly Off      Off 
session.cookie_lifetime 0        0 
session.cookie_path /            / 
session.cookie_secure Off        Off 
session.entropy_file no value    no value 
session.entropy_length 0         0 
session.gc_divisor 1000 1000 
session.gc_maxlifetime 1440      1440 
session.gc_probability 1         1 
session.hash_bits_per_character 5 5 
session.hash_function 0 0 
session.name PHPSESSID           PHPSESSID 
session.referer_check no value   no value 
session.save_handler files       files 
session.save_path c:/wamp/tmp    c:/wamp/tmp 
session.serialize_handler php    php 
session.use_cookies On           On 
session.use_only_cookies On      On 
session.use_trans_sid 0          0 

更新 - 解决方案

因为我的应用程序使用 iframe 从另一个域(我创建的)拉入页面,所以我试图设置的 cookie 被阻止.设置一个P3P头,问题似乎解决了!

Because my app was using iframes pulling in pages from another domain (which i created) the cookies i was trying to set were being blocked. Setup a P3P header and the problem seems to be solved!

推荐答案

我的建议来自 您之前的问题 仍然有效:请比较会话 ID.

My suggestion from your previous question still stands: please compare session ids.

解决方案可能就像您的浏览器不接受会话 cookie 一样简单.

The solution might be as simple as your browser not accepting session cookies.

您可以通过调用 session_id() 来检索会话 ID.在 session_start() 之后立即执行它应该给你一个常量值 如果 会话是相同的.否则,对于每个请求,都会实例化一个新会话.

You retrieve the session id by calling session_id(). Do that right after session_start() it should give you a constant value if the session is the same. Otherwise for every request a new session is instantiated.

同时检查C:wamp mp.此目录中的无数文件可能表示每个请求的新会话.

Also check C:wamp mp. A gazillion files in this directory might indicate fresh sessions for each request.

EDIT 由于我们已经确认了每个请求的新会话,现在是时候确定是否接受会话 cookie.检查浏览器的设置并确认可以找到名称为 PHPSESSID 的域的 cookie(我猜是localhost").

EDIT Since we've confirmed new sessions per request, it's time to find out whether session cookies are accepted. Check the settings of your browser and confirm that a cookie for your domain (I guess it's "localhost") with the name PHPSESSID can be found.

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

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