Link to home
Start Free TrialLog in
Avatar of mganesh
mganeshFlag for United States of America

asked on

PHP session variables problem in Firefox

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?



Avatar of Lhotch
Lhotch

Do you have cookies enabled for your firefox browser?
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.
Avatar of mganesh

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of virmaior
virmaior
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial