SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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?

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    SitePoint Enthusiast hostentic's Avatar
    Join Date
    Oct 2010
    Location
    USA
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    session_start();

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).
    my mobile portal
    ghiris.ro

  4. #4
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,101
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    After you start the session do this,
    Code:
    echo '<pre>'; print_r(); echo '</pre>';
    That will tell you what you have in your session.
    What I lack in acuracy I make up for in misteaks

  5. #5
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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
    Convert your dollars into silver coins. www.convert2silver.com

  6. #6
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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
    Convert your dollars into silver coins. www.convert2silver.com

  7. #7
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •