Firefox losing session data
Moderator: General Moderators
Firefox losing session data
I am having a very strange issue. I have a script that runs perfectly, flawlessly on all browsers on one server, but on another server, it loses my session data, but not the sessionid or the session cookie, and only in firefox. Also, making the matter more confusing, session data is not lost in other scripts on the same server, from the same web app, and all of the scripts are (theoretically) handling sessions in the same manner.
I'm not sure what information will be relevant to figuring out the solution here, so if anyone thinks they know what's going on and needs additional information, please let me know.
Some basic information: PHP5, Apache2, https website with secure cookies
Thank you
I'm not sure what information will be relevant to figuring out the solution here, so if anyone thinks they know what's going on and needs additional information, please let me know.
Some basic information: PHP5, Apache2, https website with secure cookies
Thank you
Re: Firefox losing session data
Let's start by looking at the code in the problem script.
When you post code in the forum, remember to put your code between BBCode tagsor
[/code]
Edit: This post was recovered from search engine cache.
When you post code in the forum, remember to put your code between BBCode tags
Code: Select all
[php][/php]Code: Select all
[code=php]Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:34 pm, edited 1 time in total.
Re: Firefox losing session data
Here's the parts of the code relevant to sessions.
Code: Select all
require_once('irp.php');
session_start();
if(!isset($_POST['next']) && !isset($_POST['prev']))
{
session_destroy();
session_start();
echo "destroyed session, starting over<br>";
$_POST['qnum']=0;
}
$tpl = array();
$tpl['base_url'] = pl_settings_get('base_url');
//echo $tpl['base_url'];
$tpl['title_image'] = '/images/EligibilityTitle.gif';
$tpl['title_text'] = 'Check Your Eligibility';
if(verify_answer($_POST['qnum']))
{
next_question();
}
else
{
//...unrelated code removed from here.
exit();
}
function verify_answers($qnum)
{
//...unrelated code removed from here
if(isset($sp['end']))
{
//echo "END!";
if(pass($reject_if, $type))
{
if($type !== 'income')
{
$_SESSION[$value_name] = $_POST['answer'];
}
elseif($type === 'income')
{
$_SESSION[$value_name] += $_POST['answer'];
}
//echo "<br><br><b>ACCEPTED!</b><br>";
finish();
}
}
//normal
else
{
//check conditions
if($type === 'sum')
{
$_POST['answer'] = $_SESSION[$value_name] + $_POST['answer'];
}
if(pass($reject_if, $type))
{
if($type !== 'income')
{
$_SESSION[$value_name] = $_POST['answer'];
}
elseif($type === 'income')
{
$_SESSION[$value_name] += $_POST['answer'];
}
(int)$_POST['qnum'] = isset($sp['next'])?$sp['next']:($_POST['qnum']+1);
return TRUE;
}
else
{
return FALSE;
}
}
function pass($reject_if, $type)
{
//...unrelated code removed from here
if($type==='household')
{
$adults = $_POST['adults'];
$children = $_POST['children'];
$family = $adults + $children;
$_SESSION['adults'] = $adults;
$_SESSION['children'] = $children;
$_POST['answer'] = $family;
$result = pl_query("SELECT `label` FROM `menu_poverty` WHERE `value`=$family");
if($result->numRows() == 0)
{
$result = pl_query("SELECT `label`,`value` FROM `menu_poverty` WHERE `value` IN(0,(SELECT COUNT(*) FROM `menu_poverty`)-1) ORDER BY `value`");
$row = $result->fetchRow();
$pov_zero = $row['label'];
$row = $result->fetchRow();
$pov_top = $row['label'];
$difference = $family - $row['value'];
$_SESSION['poverty'] = ($pov_top + $pov_zero*$difference)*1.25;
}
else
{
$row = $result->fetchRow();
$_SESSION['poverty'] = $row['label']*1.25;
}
return TRUE;
}
elseif($type==='income')
{
$_SESSION['income_count']++;
$income_amt = $_POST['income_amt'];
$income_freq = $_POST['income_freq'];
$income = 0;
if($income_freq == 'weekly')
{
$income = $income_amt * 52;
}
elseif($income_freq == 'bi-weekly')
{
$income = $income_amt * 26;
}
elseif($income_freq == 'monthly')
{
$income = $income_amt * 12;
}
$_SESSION['income_amt'.$_SESSION['income_count']]=$income_amt;
$_SESSION['income_freq'.$_SESSION['income_count']]=$income_freq;
$_POST['answer'] = $income;
if(!isset($_SESSION['poverty']))
{
die('household size question must come first');
}
if(($_SESSION['income']+$income) > $_SESSION['poverty'])
{
$tpl['main'] = $tpl['main']."fail";
session_destroy();
return FALSE;
}
else
{
return TRUE;
}
}
elseif(sizeof($conds) < 2)
{
return TRUE;
}
else
{
$oper = $conds[0];
$cond = $conds[1];
//check for variables
if(substr($cond,0,1)==='$')
{
$cond = substr($cond,1);
if(isset($_SESSION[$cond]))
{
$cond = $_SESSION[$cond];
}
elseif(isset($sp[$cond]))
{
$cond = $sp[$cond];
}
else
{
die("required variable $".$cond." not set");
}
}
$fail = TRUE;
//unrelated condition checking code removed from here
return !$fail;
}
}
Re: Firefox losing session data
Are you sure that $_POST['next'] and $_POST['prev'] are set every time you call the script?
Edit: This post was recovered from search engine cache.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:34 pm, edited 1 time in total.
Re: Firefox losing session data
$_POST['next'] is always set, because it's the form submit button, and the other two lines in that if block are never called.
Re: Firefox losing session data
So if you do
after your start session is it only empty with firefox on that server?
Code: Select all
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';Re: Firefox losing session data
Yes, but only in this one script.
Re: Firefox losing session data
Is the verify_answer() function called on line 20 supposed to be the same function as verify_answers() defined on line 30?
Also, the verify_answers() function definition is missing a closing curly brace.
Edit: This post was recovered from search engine cache.
Also, the verify_answers() function definition is missing a closing curly brace.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:35 pm, edited 1 time in total.
Re: Firefox losing session data
Barring the errors mcinfo found... You say this code works with other browsers, so maybe those errors are cut/paste errors.
Sorry to be anal about this but many people dump their problems in here without really looking at it. So I have to ask: Have you actually stuck in the var_dump lines at line 5 to see what is stored in $_session for firefox vs others?Belkorin wrote:Yes, but only in this one script.
Re: Firefox losing session data
Yes, I have put it there, and the previously mentioned errors are copy-paste errors.
After going through a few questions, Firefox says:
array(0) { }
IE says:
array(3) {
["i_agree"]=>
string(10) "understood"
["about_restricted"]=>
string(2) "No"
["skip3"]=>
bool(true)
}
And I know that it works on another server because it dumps all of the answer data(stored in $_SESSION) to a database when the series of questions is done.
After going through a few questions, Firefox says:
array(0) { }
IE says:
array(3) {
["i_agree"]=>
string(10) "understood"
["about_restricted"]=>
string(2) "No"
["skip3"]=>
bool(true)
}
And I know that it works on another server because it dumps all of the answer data(stored in $_SESSION) to a database when the series of questions is done.
Re: Firefox losing session data
Are you using Javascript or some other client-side scripting language to set or modify the POST variables?
Edit: This post was recovered from search engine cache.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:36 pm, edited 1 time in total.
Re: Firefox losing session data
Nope, this project is 100% client-side scripting free.
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: Firefox losing session data
Are you using Firebug on Firefox? I had some problems with it recently - try disabling it and running your script?
Re: Firefox losing session data
I probably should have mentioned this sooner. Check the contents of $_POST at the beginning of the script.
Edit: This post was recovered from search engine cache.
Code: Select all
echo '<pre>', print_r($_POST, 1), '</pre>';
exit;
Last edited by McInfo on Wed Jun 16, 2010 12:36 pm, edited 1 time in total.
Re: Firefox losing session data
I am not using firebug. This problem occurs on any computer using firefox.
Also, $_POST has the expected values in it.
Also, $_POST has the expected values in it.