Richard_Grant Posted September 13, 2014 Share Posted September 13, 2014 This is prob a stupid question.. but i've always wondered.. When deleting a cookie why do we use why do we use: setcookie($name, '', time() - 3600, "/", "", 0); when this works just fine: setcookie($name, '', 0, "/", "", 0); isn't the time() just a waste of space? I ask this because everywhere i look i see: setcookie($name, '', time() -3600 , "/", "", 0); Quote Link to comment https://forums.phpfreaks.com/topic/291029-cookies/ Share on other sites More sharing options...
Jacques1 Posted September 13, 2014 Share Posted September 13, 2014 Setting the expiration time to the past is a compatibility feature for Internet Explorer. What people miss, however, is that PHP automatically sets the expiration time when you give it an empty value. So the time() stuff doesn't do anything and is arguably a waste of space. Quote Link to comment https://forums.phpfreaks.com/topic/291029-cookies/#findComment-1490950 Share on other sites More sharing options...
Richard_Grant Posted September 13, 2014 Author Share Posted September 13, 2014 Setting the expiration time to the past is a compatibility feature for Internet Explorer. What people miss, however, is that PHP automatically sets the expiration time when you give it an empty value. So the time() stuff doesn't do anything and is arguably a waste of space. oh so i can just put ? setcookie($name, '', NULL, "/", "", 0); Without any compatibility issues? Quote Link to comment https://forums.phpfreaks.com/topic/291029-cookies/#findComment-1490953 Share on other sites More sharing options...
Jacques1 Posted September 13, 2014 Share Posted September 13, 2014 Yes. You can actually see it by inspecting the HTTP headers: The expires attribute is always “01-Jan-1970 00:00:01 GMT” (Unix time 1). Quote Link to comment https://forums.phpfreaks.com/topic/291029-cookies/#findComment-1490962 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.