Sessions have stopped working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Sessions have stopped working

Post 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.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Sessions have stopped working

Post by omniuni »

Try accessing your session variables as $_SESSION['var1'] instead.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Sessions have stopped working

Post 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)
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: Sessions have stopped working

Post 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.
Post Reply