473,396 Members | 1,895 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,396 software developers and data experts.

Session variables across multiple pages

Hi,

I'm busy fiddling with sessions under PHP5, and very quickly learned
what I would have found out even sooner in the PHP manual - declaring
your session variable on page1.php makes it available on page2.php
(assuming that's the next page you load) but doesn't then make it
available on page3.php unless you respecify it on page2.php. I'm sure
there's a very good reason for it, and I know I can get around it by
using a database and the session ID, but I would really like to know:
why? I've already searched, but can't find any more information on the
issue.

Thanks,
John Heathcote

Jul 26 '07 #1
4 10683
On 26 Jul, 12:58, John H <john.heathc...@gmail.comwrote:
Hi,

I'm busy fiddling with sessions under PHP5, and very quickly learned
what I would have found out even sooner in the PHP manual - declaring
your session variable on page1.php makes it available on page2.php
(assuming that's the next page you load) but doesn't then make it
available on page3.php unless you respecify it on page2.php. I'm sure
there's a very good reason for it, and I know I can get around it by
using a database and the session ID, but I would really like to know:
why? I've already searched, but can't find any more information on the
issue.

Thanks,
John Heathcote
You've got to be careful about your language when dealing with php and
other such languages, when considering web pages.

You have said: "declaring your session variable on page1.php".

Now do you mean "on the web page that is displaed as a result of
executing page1.php", or "in the script file page1.php".

This is important because there does not need to be a one-to-one
relationship between a .php file and a web page.

One php file may display zero, one or more than one web page.
Alternatively a web page may be made up of output from more than one
php script file.

Jul 26 '07 #2
On 26.07.2007 13:58 John H wrote:
Hi,

I'm busy fiddling with sessions under PHP5, and very quickly learned
what I would have found out even sooner in the PHP manual - declaring
your session variable on page1.php makes it available on page2.php
(assuming that's the next page you load) but doesn't then make it
available on page3.php unless you respecify it on page2.php.
This is not true. Once set, a "session variable" (more strictly, a key
in the $_SESSION array) is automatically available to all pages sharing
the same session.
--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Jul 26 '07 #3
John H wrote:
Hi,

I'm busy fiddling with sessions under PHP5, and very quickly learned
what I would have found out even sooner in the PHP manual - declaring
your session variable on page1.php makes it available on page2.php
(assuming that's the next page you load) but doesn't then make it
available on page3.php unless you respecify it on page2.php. I'm sure
there's a very good reason for it, and I know I can get around it by
using a database and the session ID, but I would really like to know:
why? I've already searched, but can't find any more information on the
issue.

Thanks,
John Heathcote
It should be available on every page you load - as long as you call
session_start() at the beginning of the page.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 26 '07 #4
On Jul 26, 3:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
John H wrote:
Hi,
I'm busy fiddling with sessions under PHP5, and very quickly learned
what I would have found out even sooner in the PHP manual - declaring
your session variable on page1.php makes it available on page2.php
(assuming that's the next page you load) but doesn't then make it
available on page3.php unless you respecify it on page2.php. I'm sure
there's a very good reason for it, and I know I can get around it by
using a database and the session ID, but I would really like to know:
why? I've already searched, but can't find any more information on the
issue.
Thanks,
John Heathcote

It should be available on every page you load - as long as you call
session_start() at the beginning of the page.
Thanks to everyone for their help - I eventually found the problem on
my side with session_start() not being declared on a few of the pages
- I've now got a require() function on my template to put in the
appropriate headers, including session_start(). Also, thanks to
Captain Paralytic - I described the problem thus to simplify matters,
but yes, I was talking about a single html page at a time with php
script inside it. Your point, however, is well taken.
Jul 27 '07 #5

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...
3
by: Jessica Loriena | last post by:
I'm trying to write a simple "register form / validate and store in database / show welcome screen" application with ASP.Net. With conventional ASP, I used Session variables and it went something...
2
by: adam | last post by:
Having spent nearly 2 years in win forms land the inevitable request came for me to "do some web pages". So being new to this bit of .net and having had a look around I can't see where the best...
6
by: Nedu N | last post by:
Hi, I am trying to design a Home page for my applicatiion in which i want show the links for for some itms... I tried to put the following <td> <font face="Arial, Helvetica, sans-serif" ...
5
by: Arun | last post by:
Hi, Is it possible to share Session/Application State across different Asp.net webapplication (one in VB.net ) and the other is C# ? If so can you guide me ? -Regards' Arun
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
14
by: Coleen | last post by:
Hi All :-) We have an APSX application using VB.net as the code behind, which uses one or two session variables per page. These Session variables are passed to the final page and calculations...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
13
by: Samir Chouaieb | last post by:
Hello, I am trying to find a solution to a login mechanism for different domains on different servers with PHP5. I have one main domain with the user data and several other domains that need...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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
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...

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.