Jump to content

Foxfire and IE6 loosing session. IE7 works as expected.


Recommended Posts

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???

 

 

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 )

Probs because you had name=name without any quotes around "name" ..

 

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'];

That wont make the slightest bit of difference!

 

You are setting an empty session value before the form is submitted using

$_POST['name']

 

 

Also use the server global for PHP_SELF:

$_SERVER['PHP_SELF']

 

Should be:

 

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;

That wont make the slightest bit of difference!

 

You are setting an empty session value before the form is submitted using

$_POST['name']

 

 

Also use the server global for PHP_SELF:

$_SERVER['PHP_SELF']

 

Should be:

 

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.

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);

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);
[/quote]

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:
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

 

 

 

 

  • 2 weeks later...

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.

 

 

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.