?
Solved

PHP Session Variables not being persistent in Firefox 3.6.9

Posted on 2010-09-14
7
Medium Priority
?
638 Views
Last Modified: 2013-12-13
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
Comment
Question by:criggs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 13

Expert Comment

by:darren-w-
ID: 33677006
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
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 33677974
Nowhere in your code do you seem to executing the compileFaciltyInfo() function, so the SESSION variables aren't being output anywhere.
0
 

Author Comment

by:criggs
ID: 33679219
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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 33680733
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
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 33690884
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
 

Author Comment

by:criggs
ID: 33695789
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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 33695882
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question