Page 1 of 1

Sessions have stopped working

Posted: Sun Dec 27, 2009 6:03 am
by spacebiscuit
Hi,

My web server host recently upgraded their hardware to and my scripts are running on a new box. However, my scripts which use session variables no longer work, or rather the session variables are not being passed correctly between scripts.

Here is the session info from the phpinfo function:

session
Session Support enabled
Registered save handlers files user sqlite
Registered serializer handlers php php_binary

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 no value no value
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 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 4 4
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path no value no value
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0

I use the following code to start a session: session_start();

And I acces and use sessions as follows:

$_SESSION[var1];

Any suggestions would be apprecaited.

Thanks,

Rob.

Re: Sessions have stopped working

Posted: Sun Dec 27, 2009 3:00 pm
by omniuni
Try accessing your session variables as $_SESSION['var1'] instead.

Re: Sessions have stopped working

Posted: Sun Dec 27, 2009 5:43 pm
by josh
It is sometimes worth peeking at the session ID in the cookie to see if it still the same session too. If you don't use the quotes PHP throws an E_NOTICE error but then should otherwise treat it the same (dont think that would stop the session from working, but it is horrible practice)

Re: Sessions have stopped working

Posted: Fri Jan 01, 2010 6:55 am
by spacebiscuit
Hi,

I solved the problem, it was because I was starting he session after the HTML began. It seems some servers are very fussy about the sessions appearing at tyhe very top of the page before the HTML headers. I know it is bad practice not to do this but some servers (my old one included) did not report any errors.

Regards,

Rob.