session_id not being pulled from cookie

Hi there,

I’m calling session_start(); as soon as my page loads but when I print out my session array it’s empty and the reason seems to be that the php session_id listed is not the same as the one stored in my cookie.

I’m not destroying the session anywhere.

Is there any way to get session_start to force getting the id from the cookie stored in the browser? I’ve verified that that ID is correct.

Thanks.

Hello,

I’m seeing that this thread has gotten quite a few views but no one has written anything. Can you tell me if it’s a dumb question?

So…what code are you using to write the cookie out?

Hy,
maybe you can get only the ID of the current session, not from a cookie, like in the next example;

<?php
session_start();

echo '<br /> The ID of the current session is: '. session_id();
?>
<?php
session_start();

$session_id = session_id();

$cookie_session_id = $_COOKIE['PHPSESSID'];

if ( $session_id === $cookie_session_id ) {
    echo 'Session ID\\'s Match!';
} else {
    echo 'Session ID\\'s Don\\'t Match!';
}

?>

Try running this code, does it report the session IDs to match?

Thanks for the feedback guys. I’m giving this a whirl now!

Guess what? It was that I’d two sites referenced. One with www and one without. Argh!!! So frustrating. :slight_smile: Thanks for the responses guys.