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?
Thanks,
Doug
--------------------------------------------------
<?php
session_start();
error_reporting(E_ALL);
$szTmp01 = '';
$szTmp01 = SID;
printf ("This is the SID = $szTmp01<br>");
if(!session_is_registered("session_id"))
{
session_register("session_id");
}
$self_url = $_SERVER['PHP_SELF'];
if(IsSet($HTTP_SESSION_VARS["session_id"]) &&
$HTTP_SESSION_VARS["session_id"])
{
$session_id = $HTTP_SESSION_VARS["session_id"];
$href = "$self_url?$szTmp01";
}
else
{
$session_id = SID;
session_register("session_id");
$href = $self_url;
}
printf ("This is the session_id = $session_id<br>");
$MyVar = LogSession();
?>
<?php
function LogSession()
{
global $session_id;
global $self_url;
global $HTTP_SESSION_VARS;
global $href;
if(!session_is_registered('session_id'))
{
$session_id = SID;
session_register('session_id');
}
$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);
fclose($fp);
return;
}
?>