Connecting Tech Pros Worldwide Help | Site Map

More on session variables

sheldonlg
Guest
 
Posts: n/a
#1: Jul 2 '08
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?
AnrDaemon
Guest
 
Posts: n/a
#2: Jul 3 '08

re: More on session variables


Greetings, sheldonlg.
In reply to Your message dated Wednesday, July 2, 2008, 22:55:38,
Quote:
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:
Quote:
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*.
Quote:
However, where do these pages get the value of $thename from?
That's undefined in your example, excluding some rare, monstrous variants...
Quote:
Also, if we reenter the base page where the session name is generated,
Session name should not be generated.
Quote:
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.
Quote:
So, here is what I see:
Quote:
in index.php:
$sessionName = 'somekindoftext' . time();
session_name($sessionName);
session_start;
Quote:
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 <anrdaemon@freemail.ru>

sheldonlg
Guest
 
Posts: n/a
#3: Jul 3 '08

re: More on session variables


AnrDaemon wrote:
Quote:
Greetings, sheldonlg.
In reply to Your message dated Wednesday, July 2, 2008, 22:55:38,
>
Quote:
>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:
>
Quote:
>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*.
>
Quote:
>However, where do these pages get the value of $thename from?
>
That's undefined in your example, excluding some rare, monstrous variants...
>
Quote:
>Also, if we reenter the base page where the session name is generated,
>
Session name should not be generated.
>
Quote:
>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.
>
Quote:
>So, here is what I see:
>
Quote:
>in index.php:
>$sessionName = 'somekindoftext' . time();
>session_name($sessionName);
>session_start;
>
Quote:
>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.
Closed Thread