Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

cookies - PHP session variables not being maintaned

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do you call session_start() on every page that accesses session data?

Edit: And do you receive the same session ID every time?
Also, could there be some error or warning you're missing (e.g. headers already sent) due to settings?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...