?
Solved

PHP session variables problem in Firefox

Posted on 2006-04-24
6
Medium Priority
?
2,871 Views
Last Modified: 2011-04-05
Hi,
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 :

index.php->page1.php->page2.php->page3.php

Here are the excerpts from the files.

index.php :

session_start();
session_register("username_session");
session_register("fullname_session");
$_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 :

session_start();
session_register("firstvar_session");
session_register("secondvar_session");

$_SESSION["firstvar_session"]=$_POST["firstvar"]
$_SESSION["secondvar_session"]=$_POST["secondar"]


page3.php:

I access session variables here

session_start();
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 :

username=ganesh
fullname=M. Ganesh
firstvar=
secondvar=

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?



0
Comment
Question by:mganesh
  • 2
4 Comments
 
LVL 7

Expert Comment

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

Expert Comment

by:virmaior
ID: 16529158
looking at your code, the lines:
session_register("firstvar_session");
session_register("secondvar_session");

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.
0
 
LVL 3

Author Comment

by:mganesh
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.
0
 
LVL 20

Accepted Solution

by:
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?)
0

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