PHP session variables problem in Firefox

Posted on 2006-04-24
Medium Priority
Last Modified: 2011-04-05
I have developed a small application for my company on PHP but have some small difficulty to overcome. In fact some session variables are getting vanished mysteriously.
Here is the flow :


Here are the excerpts from the files.

index.php :

$_SESSION["username_session"]=<value from database>
$_SESSION["fullname_session"]=<value from database>

page1.php :

Nothing related to session or session variables in this page. Just pass on a few form fields to next page.
The form fields are "firstvar" and "secondvar"

page2.php :




I access session variables here

echo "username=".$_SESSION["username_session"]."<BR>";
echo "fullname=".$_SESSION["fullname_session"]."<BR>";
echo "firstvar=".$_SESSION["firstvar_session"]."<BR>";
echo "secondvar=".$_SESSION["secondvar_session"]."<BR>";

Here is the output :

fullname=M. Ganesh

What happened to firstvar and secondvar ?

If I do a echo $_POST["firstvar"], the value is printed properly in page2.php. What happens when it is assigned to a session variable ?

Important observation : EVERYTHING IS ABSOLUTELY FINE WHEN I USE Internet Explorer! THe problem is only with Firefox !!!

Can using $_POST reset a session variable in firefox? Has this problem been observed so far by anyone?

Question by:mganesh
  • 2

Expert Comment

ID: 16525907
Do you have cookies enabled for your firefox browser?
LVL 20

Expert Comment

ID: 16529158
looking at your code, the lines:

are completely unnecessary.  Try running the same code without this.

other than this, there's no immediate explanation.  The only other possible explanation could if page2 auto redirects to page 3 using a header.  If this is the case, then the page might not end up setting the $_SESSION variables before you jump away.

generally, firefox has a tendency to hold sessons better than IE.  By this, I mean that every tab and window in FF shares the same session cookie.  In IE by contrast, opening a new window (but not from the same window) makes the entity distinct.  Opening a new window from a window which has a current session in IE will continue through.

Author Comment

ID: 16531639
To Lhotch:  Yes, Cookies are enabled.

To virmaior:  As I understand, session_register() registers a variable as a session variable so that they can be referenced througout the session.  If these are not registered as session variables, how do I carry them over to page3.php ? Kindly explain.
LVL 20

Accepted Solution

virmaior earned 2000 total points
ID: 16531714
session_register is completely unnecessary.  What is meant by registering the variable is that it now links $_SESSION['variablename'] to $variablename, not that it lets you use the variable as $_SESSION['variablename']
read the top portion of http://us2.php.net/session_register.

Also note the large number of cautions about using this function.  It's basically outdated and does more harm than good in modern php code.

that it's working in internet explorer but not firefox may just be incidental to the way they handle cookies (are your sessions functioning as client-side cookies?)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question