Solved

PHP Session Variables not being persistent in Firefox 3.6.9

Posted on 2010-09-14
7
629 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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 13

Expert Comment

by:darren-w-
Comment Utility
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 42

Expert Comment

by:Chris Stanyon
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
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
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now