• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2882
  • Last Modified:

PHP session variables problem in Firefox

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?

  • 2
1 Solution
Do you have cookies enabled for your firefox browser?
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.
mganeshAuthor Commented:
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.
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?)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now