#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    3
    Rep Power
    0
    To check if it exists, I do

    $id = session_id();
    if ($id == '') {... no session ...}

    If the $id is empty, then there is no session.

    But the problem is when I use the "session_id()" function from a different page than the page that contains the "session_start()" function, the returned $id is always empty.

    Do have I to pass the SID in the url or something? Is there a setup file that I should update?

  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    10
    Rep Power
    0
    the concept is to not look for an existing session but to look for an existing session variable... try the following:

    file page1.php
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    session_start();
    session_register("isregistered");
    $isregistered = 1;
    ?>
    <a href="page2.php?<?=SID?>">click here</a>
    [/code]

    file page2.php
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    session_start();
    if(session_is_registered("isregistered")){echo "THE SESSION EXISTS !!!";}
    else{echo "NO SESSION, BOO HOO";}
    ?>
    [/code]

    hope that helps

    --------------------
    Kryogen WebHosting - the best for PHP4
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    3
    Rep Power
    0
    I just forgot to use the session_start() function. Now things work wonders!
    Thanks!


Similar Threads

  1. start session with existing session id?
    By marco-marco in forum PHP Development
    Replies: 1
    Last Post: February 16th, 2004, 07:05 AM
  2. how do i check an index file exists in a folder?
    By Garrett_44 in forum PHP Development
    Replies: 0
    Last Post: January 4th, 2004, 11:44 AM
  3. Do compilers optimize some / into *?
    By Jason Doucette in forum C Programming
    Replies: 46
    Last Post: December 25th, 2003, 09:47 PM
  4. check if $array["key"] exists?
    By j0sh in forum PHP Development
    Replies: 4
    Last Post: December 13th, 2003, 02:24 PM
  5. Php session
    By toofe in forum PHP Development
    Replies: 1
    Last Post: December 13th, 2003, 11:59 AM

IMN logo majestic logo threadwatch logo seochat tools logo