www.webdeveloper.com
Results 1 to 4 of 4

Thread: how to check if session id has been created

  1. #1
    Join Date
    Jun 2003
    Location
    London
    Posts
    14

    how to check if session id has been created

    i want to create my own session id so i can reference it. i have the following setup:


    <?

    if (session_id()) {
    echo "session has started.";
    }
    else{
    session_start();
    $time = time();
    $date = $today = date("Ymd");
    $id = $time + $date;

    session_id($id);

    print session_id();
    echo "time = $time";
    echo "date = $date";
    }
    ?>

    This works but when i hit refresh it generates a new session, how can i check if the session id has already been made?

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try this, perhaps:

    PHP Code:
    <? 

    session_start
    (); 
    if (
    session_id()) { 
        echo 
    "session has started."

    else { 
        
    $time time(); 
        
    $date $today date("Ymd"); 
        
    $id $time $date

        
    session_id($id); 

        print 
    session_id(); 
        echo 
    "time = $time"
        echo 
    "date = $date"

    ?>

  3. #3
    Join Date
    May 2003
    Location
    Bournemouth, UK
    Posts
    34
    To test whether the session exists,

    if ($PHPSESSID) print "session exists";
    else print "session does not exist";

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    I wouldn't use global variables... Reference the session like this:

    $_SESSION["sessionid"]; #for PHP 4.1.0 and higher

    $HTTP_SESSION_VARS["sessionid"] #for lower than PHP 4.1.0

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles