473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Question Regarding Session ID

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;
}
?>


Jul 17 '05 #1
3 1902
.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
Jul 17 '05 #2
*** 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
--
Jul 17 '05 #3
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 ?
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg...
4
by: Fahad Ashfaque | last post by:
Hi, Please correct me if I go wrong anywhere in my understandings. 1- ISessionObject is created each time When any ASP Page is started executing and destroys on the page ends (not session...
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
0
by: Bryan Ax | last post by:
Quick question regarding best practices for using the AspState database for storing session variables in .NET web applications. I know I need to configure the web.config file with a database user...
2
by: Dean R. Henderson | last post by:
For an ASP.NET web application, is there a way for one session (with appropriate security authorization) to set a HttpSessionState variable to point to another session and execute the Abandon...
4
by: Jon | last post by:
All, I have a question regarding include files. I'm currently wanting to secure all of the pages within a directory by having a login script that queries a MySQL DB, and writes a session...
8
by: Roger | last post by:
I have a question regarding the behaviour of sql with OR and fetch first 1 rows only : I have a table with data : ACNO NAME TELNO CITY ZIP 1000 ...
8
by: maneeshkhare | last post by:
I have a doubt regarding the architecture, and working of the ASP.NET framework. I haven't been able to satisfy myself with any answer. I do understand that for each request for a resource...
12
by: bpw22az | last post by:
Bare with me guys. I will try and make this short and to the point. I have a website that allows students to check their admission status by submitting their email address which in turn sends them...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.