473,668 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Locatio n....)
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 1413
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($t hename);
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_registe r().
Calling session_name(), session_id() does nothing on that end.
So, here is what I see:
in index.php:
$sessionName = 'somekindoftext ' . time();
session_name($s essionName);
session_start;
in all succeeding pages:
What????
Nothing.
Create a 'session.php' like:

<?php

if(!array_key_e xist(session_na me(), $_REQUEST))
{
session_id('som ekindoftext' . 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*******@free mail.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 =
'somekindoftex t' . 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_registe r().
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_star t;
>in all succeeding pages:
What????

Nothing.
Create a 'session.php' like:

<?php

if(!array_key_e xist(session_na me(), $_REQUEST))
{
session_id('som ekindoftext' . 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
3635
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 for my session variable based security scheme. Basically, the risk is that a user will login to my site, close the window when done and allow someone else to come up to the machine, go back to my site and be logged into the previous user's...
5
4016
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 OTHER session variables are still intact !?! TIA, Larry Woods
6
2385
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 email from (possibly) three seperate forms. the following code is the end of a routine which stashes data from the first form off to session variables and then redirects itself to the proper form / procedure depending upon the state of two...
6
656
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, but I can't get the value is stored in it. How can I do that? Thanks a lot!
5
2447
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 variables and all of them are being stored into session and accessed from session and individual session object. Example: Session = "XYZ", Session=100, Session="NAME", etc.
4
5585
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 immediate window will show the values in Session after the relevant lines that set the variables in the Page_Unload event. However, on postback, these variables are no longer in Session. All Session variables that were set previous to that particular...
4
1033
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 straight afterwards. The user could do this a handful of times per visit, and although the site does not have heavy traffic currently, it needs to be scalable to do so in the future.
12
3826
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 email link gets created with an encoded query string. i.e http://www.yahoo.ca?#$@%@&#%#$@&^@%# which translates into http://www.yahoo.ca?userID=54&LocationID=Denver. Now when the user get's this email and clicks on the link I have a
0
8459
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
8374
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,...
0
8791
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8653
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
7398
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...
0
5677
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
4373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2784
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
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.