discomatt Posted July 28, 2008 Share Posted July 28, 2008 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? Quote Link to comment Share on other sites More sharing options...
Nhoj Posted July 28, 2008 Share Posted July 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 28, 2008 Author Share Posted July 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2008 Share Posted July 28, 2008 The first parameter of session_set_cookie_params() is just the lifetime in seconds. Remove time() + and see what you get. Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 28, 2008 Author Share Posted July 28, 2008 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! Quote Link to comment 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.