Hi All,

When I was testing my site in mozilla I got the following issue

I am setting session variable in my login1.php file and accessing it in hoa.php file.


this process is working properly in IE but in MOZILLA I am not able to get the value of session. and also not able to read the value set in the child window.

Please help me sort out for this issue.

Thanks.

Regards,

Gagan

Dani AI

Generated

Short summary and root causes (why IE worked but Firefox did not)

Cross‑browser session failures almost always come down to cookie/header handling or session write timing rather than a mysterious PHP bug. ’s own fix — replacing the client‑side JavaScript redirect with a server‑side redirect — is exactly the common, practical solution: server redirects let PHP finish and send the session cookie reliably. Always call session_start() before any output so PHP can send the session cookie/header. (php.net)

What actually goes wrong and how to fix it

PHP sends the session id as a Set‑Cookie header; browsers will only include that cookie on the next request if the header is accepted and the session data has been saved. If the page uses a JavaScript redirect the browser can navigate before the server has flushed the session (or privacy/SameSite rules block the cookie). Use session_write_close() (or finish the script and do a 302 server redirect) so session data is written and the lock is released before the client requests the next page. Also check cookie attributes (SameSite/Secure/HttpOnly) and browser cookie settings. (php.net)

Quick checklist (diagnose & prevent)

  • Confirm session_start() runs at the top of every page and there is no BOM/leading whitespace that forces headers out early. (php.net)
  • Use Firefox DevTools → Storage to verify a PHPSESSID cookie is set for the correct domain/path. (developer.mozilla.org)
  • If you must use client redirects, explicitly save/close the session first (session_write_close()), or prefer a server 302 + exit. (php.net)
  • If cookies are disabled (as and suggested) the session will fail; URL SID is a last resort and has security downsides — check session.use_trans_sid only with caution. (php.net)

These checks explain why ’s header redirect fixed Firefox while the JS approach did not, and they give a repeatable way to avoid the problem in future.

Recommended Answers

All 13 Replies

The only time I have had trouble with firefox and $_SESSION has been because it stores the value across multiple tabs (whereas IE doesn't) so I haven't seen your problem before. Can you please post your code for when you store the variable and when you try to access it again?

Do you possibly have cookies disabled in FF and have php configured to use a cookie to store the session id?

The only time I have had trouble with firefox and $_SESSION has been because it stores the value across multiple tabs (whereas IE doesn't) so I haven't seen your problem before. Can you please post your code for when you store the variable and when you try to access it again?

Thanks for reply,
ya sure i will tell u where i am using this.
$loginId=$_REQUEST[user];
$password=$_REQUEST[password];
$_SESSION["userId"]=$loginId;

this is working well on this page in IE and mozilla Firefox
But when i am calling this another page $_SESSION["userId"] in IE this is working well and but not in FireFox.
What is the reason. pls help me. It is very urgent.
Thanks,
Gagan

Thanks for reply,
ya sure i will tell u where i am using this.
$loginId=$_REQUEST[user];
$password=$_REQUEST[password];
$_SESSION["userId"]=$loginId;

this is working well on this page in IE and mozilla Firefox
But when i am calling this another page $_SESSION["userId"] in IE this is working well and but not in FireFox.
What is the reason. pls help me. It is very urgent.
Thanks,
Gagan

Hi gagan...
once try by using single quotes...

$loginId=$_REQUEST['user'];
$password=$_REQUEST['password'];
$_SESSION[[B]'[/B]userId[B]'[/B]]=$loginId;

Hi gagan...
once try by using single quotes...

$loginId=$_REQUEST['user'];
$password=$_REQUEST['password'];
$_SESSION[[B]'[/B]userId[B]'[/B]]=$loginId;

i have tried this . Still this is not working in mozilla firefox. It is different from IE.
Please help me . How i can sort this problem.

i have tried this . Still this is not working in mozilla firefox. It is different from IE.
when i am trying to do it . Still it is not working in firefox.
Please help me . How i can sort this problem.

The only time I have had trouble with firefox and $_SESSION has been because it stores the value across multiple tabs (whereas IE doesn't) so I haven't seen your problem before. Can you please post your code for when you store the variable and when you try to access it again?

Thanks for reply,
I am sending you URL of my site . then pls check this
http://www.warddamon.com/login/myindex.php

Open this URL in Firefox and IE both.
login name is scott
and pwd is 1234
then see the difference and then please tell me how i can sort out this problem.

This problem with sessions comes again and again. I think it was last month I help solve a simular problem. In most cases the cookie required for the session is unable to be stored inside the browser. So in otherwords, are cookies disabled in the browser that disallows sessions. So if it is mozilla firefox that sessions are not working, check that cookies are enabled. Cookies are all enabled then try using the session id in the url. Those two solutions solve most cases although the session id in the url may be a bit ugly. To use the session id in a url the following is an example of doing a link:

<?
echo '<a href="page2.php?' . SID . '">page 2</a>';
?>

Hope that helps.

gagan how did u solved your session problem?

gagan how did u solved your session issue?

gagan how did u solved your session issue?

He may take a while since earlier today he was online and might be night time in his timezone. But since I am familiar with this common problem I will ask for you to run these two test pages in the problem browser(s) to see if they work.

index.php

<? session_start();
$_SESSION['var']='test';
echo '<a href="page2.php?' . SID . '">click here to see if session are enabled.</a>';
?>

page2.php

<? session_start();
if (empty($_SESSION['var']) || !isset($_SESSION['var'])) {
echo '<b>Sessions are not enabled with this method.</b>';
} else {
echo 'Sessions work the $_SESSION[\'var\']='.$_SESSION['var'];
}

Edit: I see gagan is now online so he must spend a wider range of hours online than I thought.

Hi shaa,

yes i have solved this problem.

Actually my problem was in javascript code where you are calling your javascript code change that into php code.

Let me Explain:----Like this code was creating problem in firefox

if ($row1['isAdmin']=="Yes")
	{	
		$_SESSION["login"]="T";
		$_SESSION["admin"]="T";
		$_SESSION["userId"]=$loginId;
?>

<script type="text/javascript"> 
<!-- 
browserName=navigator.appName; 
browserVer=parseInt(navigator.appVersion); 
if ((browserName=="Netscape" && browserVer>=7.2) || (browserName=="Microsoft Internet Explorer" && browserVer>=5.5) || (browserName=="Opera" && browserVer>=7.1) || (browserName=="Mozilla Firefox" && browserVer>=1)) 
version="vernew"; 
else 
version="other"; 
/* Newer browser URL */ 
if (version=="vernew") 
window.location="admin.php?login=T"; 
/* Other browsers URL */ 
else 
window.location="admin.php?login=T"; 
//--> 
</script>

<?php
	}

I change this code into like this:-----

if ($row1['isAdmin']=="Yes")
	{	
		$_SESSION["login"]="T";
		$_SESSION["admin"]="T";
		$_SESSION["userId"]=$loginId;
		header('Location:admin.php?login=T');



	}

I think if you are facing such problem you should change ur javascript code into your php code.

I think this information will help you.

Thanks,
Gagan

also try this: start to write in your PHP file from the first character
like this:

<?

Not like this:

some spaces or some new lines <?

:-$ strange, but worked for me..
some browsers just couldn't remember session, always starting new ones, while others could..
with this it's working (and I hope will)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.