473,659 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10696
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*******@attgl obal.net
=============== ===
Jul 26 '07 #4
On Jul 26, 3:26 pm, Jerry Stuckle <jstuck...@attg lobal.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
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...
3
9409
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 like this: ***** form.asp - <form action="ValidateAndStore.asp" method="post">
2
1700
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 way to store session data. 1) use the (string)Session approach Obviously bad for maintenance, readability etc. 2) have a typed MySession object with static properties for each value I want to store
6
2561
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" color="#ffffff" size="2"> Contact | My Profile | Logout /font> </td>
5
1531
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
5304
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 copy paste (I hear this will improve in ASP.Net 2 via master pages). When I navigate from one page to the next the header and footer user controls lose their state because they are effectively different instances of the user control. Is there...
14
2185
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 and summaries are done there. In order for all of the values to appear on the last page, the user has to view each page that has a session variable to be passed to the last page. The only way I can think of to bypass the necessity of the user...
17
5086
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 guidance appreciated. Regards
22
14875
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 done in 3 steps: Step 1. Normal http login page. Step 2. A page called login.php that takes the posted username, stores it as $_SESSION, and registers it session_register("username"); user is taken to the personalized page according to his username...
13
8659
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 a login to show data. I want the user to login only once when he visits any of my domains.
0
8428
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
8337
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
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
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
7359
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
6181
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
5650
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();...
1
2754
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
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.