Unable to echo a server variable

When I view the variables that I currently have in my session, I see:

[loginCreated] => 2004-06-12

So far so good.

Then I have some code that pulls the variables out of the session that I need:

// Grab variables out of the session

$loginCreated = $_SESSION[‘loginCreated’];
$loginID = $_SESSION[‘loginID’];

In my php code, if I then do an echo $loginCreated I get:

Dec 31, 1969

I’m really not sure why this is happening, being that the date in the session is 2004-06-12. It gets even stranger. When I add the following code:

$timestamp2 = strtotime($loginCreated);
$loginCreated = date(“M d, Y”, $timestamp2);

The webpage results then show absolutely nothing. Can someone help me figure this out?


Do you have code that runs in between your two times when you are pulling your variable our of session ?

Without seeing the full code it is going to be hard to determine what exactly is going on.

Also make sure that before you try to access session variables that session is turned on if it is not done automatically by the server


Do you get any error?
It could be that the session var is not defined, that’s why you get the Unix Epoch (January 1 1970 00:00:00 GMT).

After you start the session do this,

echo '<pre>'; print_r(); echo '</pre>';

That will tell you what you have in your session.

lorenw, your suggested code produced this error:

Warning: print_r() expects at least 1 parameter, 0 given in /home3/recordau/public_html/variables.php on line 5

Oh, lorenw, I figured the error out, because I didn’t have $_session put inside the ( ). But like I said in my original post, the value in the session has always been correct. I’m just having a hard time figuring out why the date is formatted as:

Dec 31, 1969

You probably haven’t called session_start on that page. So $_SESSION[‘loginCreated’] will be empty. When you do strtotim() the result will be 0 (1 Jan 1970), which in your server’s timezone is Dec 31, 1969.

Check the value of $timestamp2 before and after calling strtotime