Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: session issue

  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    session issue

    Hi,

    I am new to php and sessions. The following code seems not to want to work.
    I have started the session and I am merely trying to check if a value exists and if so, to output it. if not, to state that the value has not been set.

    Hopefully the code is close but I ask for your assistance please.

    Code:
    <?php
    session_start(); 
    if(isset($_SESSION['sessionStartTime']))
    $sessionStartTime = ". $_SESSION['sessionStartTime'];
    echo "sessionStartTime = $sessionStartTime<br />";
    else
    echo "sessionStartime has not been defined";
    ?>
    here's the error which I do not undertsand
    Code:
    PHP Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/vhosts/myDomain/httpdocs/index.php on line 4, referer
    bazz
    Last edited by bazz; 01-10-2008 at 12:46 AM.

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    PHP Code:
    <?php
    session_start
    (); 
    if(isset(
    $_SESSION['sessionStartTime']))
    $sessionStartTime $_SESSION['sessionStartTime'];
    echo 
    "sessionStartTime = $sessionStartTime<br />";
    else
    echo 
    "sessionStartime has not been defined";
    ?>
    John

  • #3
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by bazz View Post
    Code:
    <?php
    session_start(); 
    if(isset($_SESSION['sessionStartTime']))
    $sessionStartTime = ". $_SESSION['sessionStartTime'];
    echo "sessionStartTime = $sessionStartTime<br />";
    else
    echo "sessionStartime has not been defined";
    ?>
    there are 2 problems actually the first is the wrong quoting and the other is not enclosing multiple statements in {} for the if statement

    something like this should solve ur problem
    PHP Code:
    <?php
    session_start
    (); 
    if(isset(
    $_SESSION['sessionStartTime'])) {
        
    $sessionStartTime $_SESSION['sessionStartTime'];
        echo 
    "sessionStartTime = $sessionStartTime<br />";
    } else
        echo 
    "sessionStartime has not been defined";
    ?>
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #4
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Thank you both.

    That's been a timely reminder, not to follow online tutorials just because they look the part.

    bazz


  •  

    Posting Permissions

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