473,786 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_registe r() because the site has register_global s = 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=9ebb9 5e5a3a68662c5ff 32c2db358222

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("ses sion_id"))
{
session_registe r("session_id") ;
}

$self_url = $_SERVER['PHP_SELF'];
if(IsSet($HTTP_ SESSION_VARS["session_id "]) &&
$HTTP_SESSION_V ARS["session_id "])
{
$session_id = $HTTP_SESSION_V ARS["session_id "];
$href = "$self_url?$szT mp01";
}
else
{
$session_id = SID;
session_registe r("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_V ARS;
global $href;

if(!session_is_ registered('ses sion_id'))
{
$session_id = SID;
session_registe r('session_id') ;
}

$dtime = date('r');

$session_id = $HTTP_SESSION_V ARS["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 1916
.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_regist er() because the site has register_global s = On (Hosted web
site Php Version 4.3.3).
session_registe r() is deprecated, use the $_SESSION array instead. This
way the script will also work on servers with register_global s = 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_registe r() because the site has register_global s = 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=9ebb9 5e5a3a68662c5ff 32c2db358222

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("ses sion_id"))
{
session_registe r("session_id") ;
}

$self_url = $_SERVER['PHP_SELF'];
if(IsSet($HTTP_ SESSION_VARS["session_id "]) &&
$HTTP_SESSION_V ARS["session_id "])
{
$session_id = $HTTP_SESSION_V ARS["session_id "];
$href = "$self_url?$szT mp01";
}
else
{
$session_id = SID;
session_registe r("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_V ARS;
global $href;

if(!session_is_ registered('ses sion_id'))
{
$session_id = SID;
session_registe r('session_id') ;
}

$dtime = date('r');

$session_id = $HTTP_SESSION_V ARS["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_registe r 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
4443
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 second.php) with the header("Location:") function. second.php doesn't either send any output to the browser. The browser is then send to another page also with the header() function. Now my problem: I have to send user and password data...
4
1590
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 end) while the session state (data) is originated already somewhere from where ISessionObject fetches. When user Request another page the ISessionObject is again constructed and the data from original location is loaded from there. 2- Same with...
2
3347
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 the user. I want that cookie should get deleted when user closes the browser without signing out. I think it is done in global.asa file . But i don;t know how to do it?
0
3186
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 account that can not only execute stored procedures in the AspState database, but the account needs to be able to create temporary tables, etc. as well. What do others typically do for this? Obviously, I don't want to use my sa account for this...
2
1630
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 command to close out the other session?
4
1339
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 variable confirming the user is successfully logged in. Now, I've done this many times before, however I'm getting kind of sick of putting the include file to check the session variable on EVERY page within a directory. This is especially irritating...
8
2254
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 tim 8887778888 denver 1000 tim 8887778888 denver 56465
8
1284
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 (let's talk page), we have 1 HttpApplication object from a pool that is managed by HttpApplicationFactory. My question is this. After all the objects that are created to service 1 request, is the same dll referenced for 1 page. Let's say 3 people...
12
1625
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 and our admissions office an email regarding their status in our SQL database. The ASP script that runs pulls all information from one table. There are three possible status types; 'AC (App Complete), AI (App Incomplete), and UR (Under Review)'. ...
0
9650
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.