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

PHP Session Variables not being persistent in Firefox 3.6.9

I am trying to convert an application from IE7 to make it compatible with Firefox. I have found that the session variables are not being persistent from one php page to another.  For example this code is in a file that is called first.  The session variables are set here:
 
<?php
require_once('startSession.php');
session_start();
require_once('connectVars.php');

$pageTitle = "Sonsio Locator Remove or Edit Page";
$style = '';
$script = 'js/remove.js';

require_once('header.php');
require_once('navBar.php');

$facility = $_POST['facility'];
$telephone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$entityID = $_POST['entityID'];
$programCat = $_POST['program'];
$productID = $_POST['product'];

echo '<br />$facility = ' . $facility . '<br />';

$_SESSION['retURL'] = $_SERVER['HTTP_REFERER'];
$_SESSION['entityID'] = $entityID;
$_SESSION['facility'] = $facility;
$_SESSION['telephone'] = $telephone;
$_SESSION['address'] = $address;
$_SESSION['combined'] = $city . ', ' . $state . ' ' . $zip . ' ' . $country; 
$_SESSION['programCat'] = $programCat;
$_SESSION['productID'] = $productID;


?>

Open in new window


Then the next php page that is called cannot find the session variables:

<?php
require_once('startSession.php');
session_start();
require_once('connectVars.php');
	//editNotes
	$editNotes = $_POST['editNotes'];
	//removeReason & editNotes
	$removeReason = $_POST['removeReason'];
	$removeNotes = $_POST['removeNotes'];

	if($editNotes != '') {
		//generate edit email
		generateEditEmail($editNotes);
	}
	else {
		//generate remove email
		generateRemoveEmail($removeReason, $removeNotes);
	}
	

function compileFaciltyInfo() {
	$facilityInfo = "Submitted by: " . $_COOKIE['fullName'] .
	"\nEntityID: " . $_SESSION['entityID'] . 
	"\nFacility: " . $_SESSION['facility'] .
	"\n" . $_SESSION['address'] .
	"\n" . $_SESSION['combined'] .
	"\n" . $_SESSION['telephone'] .
	"\n" . $_SESSION['programCat'] .
	"\n" . $_SESSION['ProductID'] ;
echo '<br />In compileFacilityInfo and $facilityInfo = ' . $facilityInfo; 
	return $facilityInfo;
} // of function compileFacilityInfo	

Open in new window


The startSession.php looks like this:
<?php
  session_start();

  // If the session vars aren't set, try to set them with a cookie
  if (!isset($_SESSION['userID'])) {
    if (isset($_COOKIE['userID']) && isset($_COOKIE['username'])) {
      $_SESSION['userID'] = $_COOKIE['userID'];
      $_SESSION['username'] = $_COOKIE['username'];
	  $_SESSION['email'] = $_COOKIE['email'];
    }
  }
?>

Open in new window



Does anyone know why IE7 would work just fine, but Firefox can't see the session variables?

Thanks for your help.
0
criggs
Asked:
criggs
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
darren-w-Commented:
try putting  session_start(); as the first line on your ' next page,' you may have problems having calling it in the include.

http://www.tizag.com/phpT/phpsessions.php
0
 
Chris StanyonCommented:
Nowhere in your code do you seem to executing the compileFaciltyInfo() function, so the SESSION variables aren't being output anywhere.
0
 
criggsAuthor Commented:
Yes, I am calling that function down below. I just didn't include all the code...it would get quite lengthy. The reason I know that the session variables aren't being found is the echo line in the function. When the function is called it only echo's "In compileFacilityInfo and $facilityInfo = ".
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Chris StanyonCommented:
OK,

I can't really see any other problems with the code that's posted so I'm guessing that there's a problem somewhere else.

Are you sure you're not calling session_destroy() or unset() any where in your code. Also, in your pages, you can try adding the following line of code

print_r($_SESSION);

That will print out all the session variables. For example, call it straight after setting the session vars to make sure they are set, and then call it again in your other pages - make sure it's called after session_start().

You don't need the session_start() call at the beginning of each of your pages because it's already inside the included file.


0
 
Ray PaseurCommented:
If sessions work differently between FF and IE, you almost certainly have either (1) a cookie-related problem or (2) some kind of conditional logic that detects the browser.  Are you testing with only one instance of the browser window open?  It may go without saying, but cookies set on the IE browser are invisible to the FF browser and vice versa.

Your sessions are working correctly if this code runs correctly, incrementing the "cheese" counter.
<?php // RAY_session_test.php
error_reporting(E_ALL);

// MAN PAGE HERE: http://us.php.net/manual/en/function.session-start.php

// START THE SESSION (DO THIS FIRST, UNCONDITIONALLY, IN EVERY PHP SCRIPT ON EVERY PAGE)
session_start();

// SEE IF THE SUBMIT BUTTON WAS CLICKED
if (isset($_POST['fred']))
{
    // SEE IF THE CHEESE VARIABLE IS SET IN THE SESSION ARRAY
    if(!isset($_SESSION['cheese']))
    {
        // IF CHEESE IS NOT SET, SET IT TO ONE
        $_SESSION['cheese'] = 1;
    }
    else
    {
        // IF CHEESE IS SET, ADD ONE TO IT
        $_SESSION['cheese']++;
    }
}
// END OF SCRIPT - SUPPRESS NOTICES IN THE HTML PART
error_reporting(E_ALL ^ E_NOTICE);
?>
<html>
<head>
<title>Session Test</title>
</head>
<body>
Currently, $_SESSION["cheese"] contains: <?php echo $_SESSION['cheese']; ?> <br/>
<form method="post">
<input type="submit" value="click" name="fred">
</form>
</body>
</html>

Open in new window

0
 
criggsAuthor Commented:
Ray:

Thank you for the response.  I have run the script you provided and the session is incrementing correctly.  If I understand you correctly that means that something is wrong with cookies or logic previous to this.  I will go through my code meticulously to find it!  I am not testing for browsers within PHP.  There is some browser testing happening in the javascript.
0
 
Ray PaseurCommented:
In the Javascript?  Hmm... Might want to post that JavaScript in the JavaScript Zone here and see if someone over there can pick up something.  It's a pretty active zone with some great talents.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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