This is a discussion on Question Regarding Session ID within the PHP Language forums, part of the PHP Programming Forums category; I'm new to session id variables. I'm trying to write records containing the session id to a log ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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; } ?> |
|
|||
|
.oO(Douglas Pollock)
>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). session_register() is deprecated, use the $_SESSION array instead. This way the script will also work on servers with register_globals = Off. >Can anyone explain what I'm doing wrong and why SID does not seem to have or >retain a value? SID is only set if the client rejects the session cookie. Micha |
|
|||
|
*** Michael Fesser escribió/wrote (Thu, 03 Mar 2005 19:34:37 +0100):
> SID is only set if the client rejects the session cookie. The OP is probably looking for session_id(): string session_id ( [string id] ) session_id() returns the session id for the current session. http://www.php.net/session_id -- -+ Álvaro G. Vicario - Burgos, Spain +- http://www.demogracia.com (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 -- |
|
|||
|
Douglas Pollock wrote:
> 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; > } > ?> > > > > 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 ? |