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

Link to comment
Share on other sites

It's true for IE 7 as well, on 4 different machines :(

 

I wonder why PHP sets it's own session cookie differently than setcookie(). I may just have to create my own custom session class.

 

Thanks for the help though.

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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.