Jump to content

PHP, Session Cookies, and IE 6


discomatt

Recommended Posts

I'm hoping this is just an isolated issue... but I'm having issues with the following little snippet.

 

<?php
ob_start();

if (  isset( $_COOKIE['some_sess'] )  )
echo 'Previous session cookie found';
else
echo 'No existing session cookie exists';

echo '<br />';

if (  isset( $_COOKIE['some_cookie'] )  )
echo 'Manual cookie found';
else {
setcookie( 'some_cookie', '1', time() + 60*60*24 );
echo 'No manual cookie exists -> Created.';
}

session_name( 'some_sess' );
session_set_cookie_params( time() + 60*60*24 );
session_start();

echo '<pre>';
print_r( $_COOKIE );
echo '</pre>';

ob_end_flush();
?>

 

What I'm trying to accomplish is to create a session cookie that doesn't expire when the browser closes.... in this case, last for a day. This works as expected on my install of FireFox ( XP ) -> The first visit to the page returns 'no cookie'. After closing the browser completely and re-visiting the page, it returns 'cookie found.' Exactly what I want it to do.

 

In IE 6, or at least, my install of IE 6 ( I've set to fairly lax security/privacy settings, so I can't see why it would be isolated ) the first visit returns 'no cookie' as expected - a refresh will return 'cookie found', but once the browser is closed and re-opened, the cookie is gone. The weird part is, if I set a cookie manually via setcookie(), IE 6 finds it no problem after a browser close.

 

Help? :D

Link to comment
https://forums.phpfreaks.com/topic/117039-php-session-cookies-and-ie-6/
Share on other sites

IE6 has some funkie session handling. Honestly, if you can figure it out that would be great. I've spent probably 10 - 12 hours on the same issue in the past and gave up. It's a very common issue: http://www.google.com/search?hl=en&q=IE6+and+php+sessions. Also there are a few suggestions for headers you can set that can be found on php.net.

The first parameter of session_set_cookie_params() is just the lifetime in seconds. Remove time() + and see what you get.

 

Wonderful, should've looked closer. I just figured it was timeout like setcookie(). Seems to be working, thanks!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.