Cookie Checking in PHP

Today I added cookie checking to BeTwittered, BeTWiTted and Identify.  It was pretty simple once I jumped in and just started.  It was made a bit easier, too, due to the fact that they all start with a logon screen. 

Basically what I did was to write a cookie called "today" setting the value to todays date.  I specifically set it using this PHP code:

setcookie('today', date('mdy'), time()+7257600);
// 7257600 seconds=12 weeks - dont ask why, just 12 weeks.


Now if you were to return to the logon screen due to a failed logon, I have a "today" check in place:

if($_COOKIE['today']!=date('mdy')){...}

The if statement calls back the logon screen with an additional note that lets you know that cookies dont seem to be allowed for betwittered.com (the domain hosting the apps) 

The pitfall to keep in mind if you don't already know how to do this: Cookies are NOT available to PHP until the request following the setcookie() call.  Remember that the cookie comes along in the next HTML header AFTER it's set.  To put it simply, you must reload the page after setting the cookie in order to check to see if it was set. 

It's also worth noting that I chose to use the date as the cookie value because someone might allow cookies today, then install something or change a setting to later block cookies.  By checking for todays date in the cookie I know if cookies can be set today.

Do you have a better way, or an improvement?  Lemme know!

Comments

Update: I've since dropped

Update: I've since dropped this method and gone to use of javascript cookie checking on the client side. Unlike PHP, javascript writes cookies immediately and so are immediately useable. This means you can write a cookie (e.g. the current time) and the check to see if the value was written. Much more elegant and adaptable if you happen to be working in javascript and not just PHP.