HeidiR Posted November 6, 2008 Share Posted November 6, 2008 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/ Share on other sites More sharing options...
Adam Posted November 6, 2008 Share Posted November 6, 2008 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']; Quote Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/#findComment-683566 Share on other sites More sharing options...
JonnoTheDev Posted November 6, 2008 Share Posted November 6, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/#findComment-683704 Share on other sites More sharing options...
HeidiR Posted November 6, 2008 Author Share Posted November 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/#findComment-683768 Share on other sites More sharing options...
JonnoTheDev Posted November 6, 2008 Share Posted November 6, 2008 Try out the modified code on a test page and see if that works as expected. Quote Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/#findComment-683781 Share on other sites More sharing options...
fanfavorite Posted November 6, 2008 Share Posted November 6, 2008 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 Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/#findComment-683785 Share on other sites More sharing options...
HeidiR Posted November 6, 2008 Author Share Posted November 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/#findComment-683932 Share on other sites More sharing options...
HeidiR Posted November 17, 2008 Author Share Posted November 17, 2008 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'); Quote Link to comment https://forums.phpfreaks.com/topic/131613-foxfire-and-ie6-loosing-session-ie7-works-as-expected/#findComment-692206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.