PHP session values lost after redirect on one script but preserved after redirection on another.

Posted by Iuhiz on Stack Overflow See other posts from Stack Overflow or by Iuhiz
Published on 2010-05-25T03:59:31Z Indexed on 2010/05/25 4:11 UTC
Read the original article Hit count: 226

Filed under:
|
|

On my registration script i have:

// Save registration information into the database

// Set sessions
$_SESSION['var1'] = 'somevalue';
$_SESSION['var2'] = 'anothervalue';

header('Location: /somewhere');
exit();

Then on my login script i have:

// Check if user provided correct login credentials
if (correct) {
    $_SESSION['var1'] = 'somevalue';
    $_SESSION['var2'] = 'anothervalue';
}

header('Location: /somewhere');
exit();

What happened is that the session variables were lost after the header redirect in the registration script but they were preserved after the redirect in the login script.

I've checked session_id() at both pages and they have the same value, included session_start() at the top of every page and basically tried the solutions to this common problem found on Stackoverflow but somehow nothing seemed to work.

I'm beginning to wonder if it is something to do with my server configuration instead of my code.

© Stack Overflow or respective owner

Related posts about php

Related posts about session