Author Topic: Foxfire and IE6 loosing session. IE7 works as expected.  (Read 408 times)

0 Members and 1 Guest are viewing this topic.

Offline HeidiRTopic starter

  • Irregular
  • Posts: 10
    • View Profile
Foxfire and IE6 loosing session. IE7 works as expected.
« on: November 06, 2008, 06:00:15 AM »
Hello All,

I have run into an issue where Foxfire and IE6 are loosing session information. However, running the same php program in IE7 works as expected. Test code is below. What am I missing???


Code: [Select]
session_start();

print_r($_POST);
print_r($_SESSION);

$str = "<form method=post action=" . $PHP_SELF . ">";
$str .= "<input name=name type=text>";
$str .= "<input name=cmd type=submit value=Send>";
$str .= "</form>";
echo($str);

$_SESSION['name'] = $_POST['name'];



IE6 and Fox Results:
Array ( [name] => aaa [cmd] => Send )
Array ( )

IE7 Results:
Array ( [name] => aaa [cmd] => Send )
Array ( [name] => xxx )

Online Adam

  • Guru
  • Fanatic
  • *
  • Posts: 4,702
  • Gender: Male
    • View Profile
Re: Foxfire and IE6 loosing session. IE7 works as expected.
« Reply #1 on: November 06, 2008, 06:20:53 AM »
Probs because you had name=name without any quotes around "name" ..

Code: [Select]
session_start();

print_r($_POST);
print_r($_SESSION);

$str = '<form method="post" action="' . $PHP_SELF . '">';
$str .= '<input name="name" type="text">';
$str .= '<input name="cmd" type="submit" value="Send">';
$str .= '</form>';

echo $str;

$_SESSION['name'] = $_POST['name'];
Ronnie Wood, true or false?

Offline neil.johnson

  • Guru
  • Fanatic
  • *
  • Posts: 3,416
  • Gender: Male
    • View Profile
Re: Foxfire and IE6 loosing session. IE7 works as expected.
« Reply #2 on: November 06, 2008, 10:42:22 AM »
That wont make the slightest bit of difference!

You are setting an empty session value before the form is submitted using
Code: [Select]
$_POST['name']

Also use the server global for PHP_SELF:
Code: [Select]
$_SERVER['PHP_SELF']
Should be:

Code: [Select]
session_start();
 
    // set the session
    if(isset($_POST['cmd']) && $_POST['cmd'] == 'Send') {
      if(strlen($_POST['name'])) {
          $_SESSION['name'] = $_POST['name'];
          print_r($_SESSION);
          exit();
      }
    }

$str = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
$str .= '<input name="name" type="text">';
$str .= '<input name="cmd" type="submit" value="Send">';
$str .= '</form>';
echo $str;

« Last Edit: November 06, 2008, 10:43:36 AM by neil.johnson »
Quote
To start, press any key. Where's the 'Any' key?

Offline HeidiRTopic starter

  • Irregular
  • Posts: 10
    • View Profile
Re: Foxfire and IE6 loosing session. IE7 works as expected.
« Reply #3 on: November 06, 2008, 11:56:37 AM »
That wont make the slightest bit of difference!

You are setting an empty session value before the form is submitted using
Code: [Select]
$_POST['name']

Also use the server global for PHP_SELF:
Code: [Select]
$_SERVER['PHP_SELF']
Should be:

Code: [Select]
session_start();
 
    // set the session
    if(isset($_POST['cmd']) && $_POST['cmd'] == 'Send') {
      if(strlen($_POST['name'])) {
          $_SESSION['name'] = $_POST['name'];
          print_r($_SESSION);
          exit();
      }
    }

$str = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
$str .= '<input name="name" type="text">';
$str .= '<input name="cmd" type="submit" value="Send">';
$str .= '</form>';
echo $str;


Thanks for the quick reply. In this example, session will be empty on the first pass. After a value is entered into the name field, session should contain the entered text. Firefox and IE6 are loosing session information. However, running the same php program in IE7 works as expected.

Offline neil.johnson

  • Guru
  • Fanatic
  • *
  • Posts: 3,416
  • Gender: Male
    • View Profile
Re: Foxfire and IE6 loosing session. IE7 works as expected.
« Reply #4 on: November 06, 2008, 12:17:39 PM »
Try out the modified code on a test page and see if that works as expected.
Quote
To start, press any key. Where's the 'Any' key?

Offline fanfavorite

  • Enthusiast
  • Posts: 369
  • Gender: Male
    • View Profile
    • Another Take Studios Inc.
Re: Foxfire and IE6 loosing session. IE7 works as expected.
« Reply #5 on: November 06, 2008, 12:23:00 PM »
In your example, you wouldn't see the $_SESSION until you refreshed.

1st Pass:  $_SESSION prints and $_SESSION['name'] is not set
2nd Pass:  $_SESSION prints nothing because it still is not declared, $_SESSION['name'] gets declared after the print
3rd Pass:  Old $_SESSION prints and then new post changes to $_SESSION['name']

Try rearranging it a bit:

session_start();

$_SESSION['name'] = $_POST['name'];

print_r($_POST);
print_r($_SESSION);

$str = "<form method=post action=" . $_SERVER[PHP_SELF] . ">";
$str .= "<input name=name type=text>";
$str .= "<input name=cmd type=submit value=Send>";
$str .= "</form>";
echo($str);

Offline HeidiRTopic starter

  • Irregular
  • Posts: 10
    • View Profile
Re: Foxfire and IE6 loosing session. IE7 works as expected.
« Reply #6 on: November 06, 2008, 02:44:15 PM »
In your example, you wouldn't see the $_SESSION until you refreshed.

1st Pass:  $_SESSION prints and $_SESSION['name'] is not set
2nd Pass:  $_SESSION prints nothing because it still is not declared, $_SESSION['name'] gets declared after the print
3rd Pass:  Old $_SESSION prints and then new post changes to $_SESSION['name']

Try rearranging it a bit:

session_start();

$_SESSION['name'] = $_POST['name'];

print_r($_POST);
print_r($_SESSION);

$str = "<form method=post action=" . $_SERVER[PHP_SELF] . ">";
$str .= "<input name=name type=text>";
$str .= "<input name=cmd type=submit value=Send>";
$str .= "</form>";
echo($str);

Thanks for the suggestions guys! I tried both code sample and they worked as expected but unfortunately did not solve my problem. What I am look for is the value of the POST variable from the previous pass not the current pass.

My original test code was:
Code: [Select]
session_start();

print_r($_POST);
print_r($_SESSION);

$str = "<form method=post action=" . $PHP_SELF . ">";
$str .= "<input name=name type=text>";
$str .= "<input name=cmd type=submit value=Send>";
$str .= "</form>";
echo($str);

$_SESSION['name'] = $_POST['name'];

Running this code on IE7 produces the following results:
First pass:
Array ( [name] => abc [cmd] => Send )
Array ( [name] => )

Second pass:
Array ( [name] => xyz [cmd] => Send )
Array ( [name] => abc )

Third pass:
Array ( [name] => 123 [cmd] => Send )
Array ( [name] => xyz )


Running this code on IE6 and Firefox produces the following results:
First pass:
Array ( [name] => abc [cmd] => Send )
Array ( [name] => )

Second pass:
Array ( [name] => xyz [cmd] => Send )
Array ()

Third pass:
Array ( [name] => 123 [cmd] => Send )
Array ()

Note that there is nothing in the session array for the IE6 / Firefox passes. What am I missing???

Thanks HeidiR




Offline HeidiRTopic starter

  • Irregular
  • Posts: 10
    • View Profile
Re: Foxfire and IE6 loosing session. IE7 works as expected. [SOLVED]
« Reply #7 on: November 17, 2008, 02:49:35 PM »
Hello All,

After some additional research and testing, I found the following two causes of the issue:

1) Firefox and IE6 were not accepting cookies
2) ini_set(’session.use_trans_sid’, 1) can not be set by php to enable sessions to work without cookies.
 
The solution I implemented was to test if cookies are enabled using the code below. However, this will only let you know if cookies are enabled or not. Any logic dependent on session vars with cookies NOT enabled will fail.


Code: [Select]
setcookie ('cookies_enabled', '1', time() + 60);
if ($_COOKIE['cookies_enabled'])
echo('Cookies enabled');
else
echo('Cookies are NOT enabled');