473,397 Members | 1,969 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.

More on session variables

I wanted to see if absolute or relative URLs had anything at all to do
with the session variable information being lost. So, I wrote a simple
test program. It is at www.sheldonlg.com/headertest/index.php. The
results were not what I expected. BOTH ways lost the session information.

All this test application does is call session_name to set a name. Then
session_start. It prints out the name and dumps the session variables.
It has two buttons, one for absolute header path and one for relative
path. Each is a submit butto that goes to a page where the test is made
as the the source of the click and then uses a header("Location....)
command to go to one of two different pages. Each of those pages dumps
the session variables and the session name, and all pages (other than
the index page described earlier) has session_start(); as the first
executable line.

What happens is that the session variables are lost and the session
names become PHPSESSID, the default.

What is wrong here? It seems so exceedingly elementary. I have done
this process so many times to set and later read session variables that
is has become second nature to me. Why is it not working in this very
simple application?
Jul 2 '08 #1
2 1387
Greetings, sheldonlg.
In reply to Your message dated Wednesday, July 2, 2008, 22:55:38,
Here is what I would like to do, but there seems to be a chicken and egg
situation. I would like to name the session as $thename =
'somekindoftext' . time(); I want to do this upon entering the base
page. Now, as I understand it, on every page I would then have:
session_name($thename);
session_start();
It looks you want to generate session id, not session name.
Let me explain.
session_name() - sets the NAME of the session variable that will be used to
track sessions. It is the same for all users, and session_start looking for it
to retrieve session id.
session_id() - sets the actual session identifier, representing exact user who
browsing your pages. Actual "name" of the *user*.
However, where do these pages get the value of $thename from?
That's undefined in your example, excluding some rare, monstrous variants...
Also, if we reenter the base page where the session name is generated,
Session name should not be generated.
does that start a whole new session and we would lose all prior information
from the previous named session?
Session started by calling session_start() or session_register().
Calling session_name(), session_id() does nothing on that end.
So, here is what I see:
in index.php:
$sessionName = 'somekindoftext' . time();
session_name($sessionName);
session_start;
in all succeeding pages:
What????
Nothing.
Create a 'session.php' like:

<?php

if(!array_key_exist(session_name(), $_REQUEST))
{
session_id('somekindoftext' . strval(time()));
}

session_start();

?>

and include it in every your file that require session handling.

P.S.
I've had real use of custom session ids only once:
When I had to write CLI PHP script which were want to store some data between
runs. I've used constant session ID made from script name and version to
restart previously saved session.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jul 3 '08 #2
AnrDaemon wrote:
Greetings, sheldonlg.
In reply to Your message dated Wednesday, July 2, 2008, 22:55:38,
>Here is what I would like to do, but there seems to be a chicken and egg
situation. I would like to name the session as $thename =
'somekindoftext' . time(); I want to do this upon entering the base
page. Now, as I understand it, on every page I would then have:
>session_name($thename);
session_start();

It looks you want to generate session id, not session name.
Let me explain.
session_name() - sets the NAME of the session variable that will be used to
track sessions. It is the same for all users, and session_start looking for it
to retrieve session id.
session_id() - sets the actual session identifier, representing exact user who
browsing your pages. Actual "name" of the *user*.
>However, where do these pages get the value of $thename from?

That's undefined in your example, excluding some rare, monstrous variants...
>Also, if we reenter the base page where the session name is generated,

Session name should not be generated.
>does that start a whole new session and we would lose all prior information
from the previous named session?

Session started by calling session_start() or session_register().
Calling session_name(), session_id() does nothing on that end.
>So, here is what I see:
>in index.php:
$sessionName = 'somekindoftext' . time();
session_name($sessionName);
session_start;
>in all succeeding pages:
What????

Nothing.
Create a 'session.php' like:

<?php

if(!array_key_exist(session_name(), $_REQUEST))
{
session_id('somekindoftext' . strval(time()));
}

session_start();

?>

and include it in every your file that require session handling.

P.S.
I've had real use of custom session ids only once:
When I had to write CLI PHP script which were want to store some data between
runs. I've used constant session ID made from script name and version to
restart previously saved session.

Thanks, that makes a lot of sense.
Jul 3 '08 #3

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

Similar topics

9
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk...
5
by: Larry Woods | last post by:
I am losing Session variables, but only those that are set in the page previous to a redirect to a secure page. Anyone seen ANY situation where Session variables just "disappear?" Note that...
6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
6
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
5
by: Abhilash.k.m | last post by:
This is regarding the session management using Out of proc session management(SQL SERVER). Among the samples below which one is better to set the session? 1. There are 20 session...
4
by: PJ | last post by:
A particular page seems to be having issues with correctly setting Session variables. I am setting a couple of session variables on the Page_Unload event. While stepping through code, the...
4
by: Grant Merwitz | last post by:
Hi I currently have a web site that utilises sessions on a particular page. When a user clicks a button on this page, a session is created for the duration of the request, and then terminated...
12
by: MrHelpMe | last post by:
Hello again all, I've finished my whole application and now I don't like the whole session variables that I am using. I have a form, user fills in info clicks submit and using CDOSYSMail an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
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.