#58: Checking to See If a User's Browser Accepts Cookies

To see if a browser accepts cookies, you must check in two distinct steps, in two distinct web requests. The client's browser must make two requests because the browser sets a cookie only when it gets a response from the first request.

You can serve both requests with one script, but you have to be careful not to put the browser in an infinite loop. The idea is to check for the cookie, and if the cookie is not set, you must try to set it and reload the page. But you want to reload only once, so you also have to tell the script that it is doing a reload to prevent it from loading yet again if the cookie is not set.

This is a small script, but because you run the risk of infinitely reloading ...

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.