Question Regarding Session ID

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm new to session id variables. I'm trying to write records containing the
session id to a log file but the session id keeps disappearing. I'm using
session_register() because the site has register_globals = On (Hosted web
site Php Version 4.3.3).

If I work on my local Windows XP computer and I start up a browser window
the first printf statement
printf ("This is the SID = $szTmp01<br>"); results in:

This is the SID =

Which is blank. The second print statement gives.
This is the session_id = PHPSESSID=9ebb95e5a3a68662c5ff32c2db358222

which seems to work Ok.

When I execute the script on the hosted web site the result is:
This is the SID =
This is the session_id =

Can anyone explain what I'm doing wrong and why SID does not seem to have or
retain a value?



  $szTmp01 = '';

  $szTmp01 = SID;
  printf ("This is the SID = $szTmp01<br>");


  $self_url = $_SERVER['PHP_SELF'];
  if(IsSet($HTTP_SESSION_VARS["session_id"]) &&
    $session_id = $HTTP_SESSION_VARS["session_id"];
    $href = "$self_url?$szTmp01";
    $session_id = SID;
    $href = $self_url;
  printf ("This is the session_id = $session_id<br>");
  $MyVar = LogSession();


  function LogSession()
    global $session_id;
    global $self_url;
    global $HTTP_SESSION_VARS;
    global $href;

      $session_id = SID;

    $dtime = date('r');

    $session_id = $HTTP_SESSION_VARS["session_id"] ;

    $rec_log = "Date: $dtime | SID: $session_id \n";
    $fp = fopen("SLog/logs.txt", "a");
    fputs($fp, $rec_log);


Re: Question Regarding Session ID

Douglas Pollock wrote:
Quoted text here. Click to load it
you don't need all this stuff, all you need to do is have an object that
instantiates a session at the top of the code. In fact you don't even
need to do that. the only essential thing in the above code is
session_register which should be unconditional 'cos it will use an
existing session or create one if a session don't exist.

As to the rest of it, well be a control freak if you must, but why
capture this information ?

Re: Question Regarding Session ID

 .oO(Douglas Pollock)

Quoted text here. Click to load it

session_register() is deprecated, use the $_SESSION array instead. This
way the script will also work on servers with register_globals = Off.

Quoted text here. Click to load it

SID is only set if the client rejects the session cookie.


Re: Question Regarding Session ID

*** Michael Fesser escribió/wrote (Thu, 03 Mar 2005 19:34:37 +0100):
Quoted text here. Click to load it

The OP is probably looking for session_id():

string session_id ( [string id] )
session_id() returns the session id for the current session.

-+ Álvaro G. Vicario - Burgos, Spain
+- (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox

Site Timeline