PHP会话变量不是maintaned [英] PHP session variables not being maintaned

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

问题描述

我有一个应用程序已经使用会话变量没有问题。我在每个页面上的标题之前启动会话使用什么时候,它已经很好,然后似乎突然,我得到一个未定义的索引错误,当我导航到一个页面而不是设置会话变量。 但仅限某些浏览器。有时会话会保持,有时候不会。



似乎Cookie在某些时候不会被存储。我使用不同的浏览器做了检查,有时cookie是存储,有时不是。



我做了一个实验。我使用firefox来使用应用程序,我一直在保持会话存储的tmp文件夹。我清理掉了。使用firefox我开始使用应用程序,使用所有的会话正在使用的页面,最后我检查了tmp文件夹,它有一个会话文件。



与internet explorer完全相同,现在有7个不同的会话文件。



我使用PHP 5.3.0与WAMP堆栈。 Apache 2.2.11。会话支持在我的phpinfo()中启用。



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

 <?php var_dump($ _ SESSION); ?> 

array(0){}

任何人都可以帮我找出

UPDATE - PHP INI SESSION设置



 指令本地值主值
session.auto_start关闭
session.bug_compat_42打开
session.bug_compat_warn打开打开
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain 82.68.26.169 82.68.26.169
session.cookie_httponly关闭
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure关闭
session.entropy_file没有价值没有价值
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无值无值
session.save_handler文件文件
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

UPDATE - 解决方案



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

解决方案

我的建议来自您先前的问题仍然显示:请比较会话ID



解决方案可能与您的浏览器不接受会话Cookie一样简单。



您检索会话ID通过调用 session_id()。在 session_start()之后,应该给出一个常量值如果会话是相同的。否则,每个请求都会实例化一个新会话。



同时检查 C:\wamp\tmp



EDIT 由于我们已根据每个请求确认了新的工作阶段,查看是否接受会话Cookie。检查您的浏览器的设置,并确认您的域(我猜是localhost)的名称 PHPSESSID 的cookie可以找到。


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.

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.

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.

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

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

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?

UPDATE - PHP INI SESSION settings

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 

UPDATE - Solution

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!

解决方案

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

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

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.

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

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会话变量不是maintaned的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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