Problems with Sessions

Hi there

I’m having a really frustrating problem with Sessions in PHP. I have code that is working fine for cookies, but Sessions are not persisting across multiple pages: the session is set and shows properly if I don’t redirect to another page, but once i get to the 2nd page, the Session doesn’t show.

I have session_start(); at the top of both pages (its in the dsn, which is included at the top of every page).

The code that sets the Session is:

$_Session['temp'] = "yes";
session_write_close();
header('Location: mainmenu.php');

If I kill the redirect, I can print the session to the local page.

in mainmenu.php I’m trying to retrieve it with:

<?php echo $_Session['temp']; ?>

Nothing shows.

The php.ini for Session data is:

[Session]
session.save_handler = files
session.save_path = “/hsphere/local/home/c338405/”
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = “/”
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = “a=href,area=href,frame=src,input=src,form=fakeentry”

I DO see Sessions written on the server, but they seem to be empty…?

Can anyone help with this?

Thanks!

Hi there,

Did you start your PHP scripts with session_start()? In order for SESSION variables to be used and called, you have to start all of your scripts using them with that command.

Hope that helps.

Yes, I have session_start() in the dsn which is called on every page, so it’s persistent throughout.

Sponsor our Newsletter | Privacy Policy | Terms of Service