What's the best way to check if cookies are enabled?




Is there a way to find out if cookies are enabled in PHP?
I'm using session variables to log in users, but it doesn't work if cookies are not enabled. I guess one way is to register a session variable and check on the next script if ISSET. Is that the best way? Or is it possible to find out within the same script, maybe using javascript?

Many thanks,
Search you PHP ini for session.use_cookies. Set it to ON.
However users' browsers must have cookies anabled too for this to work.

Yes, a great idea is to use cookies to "remember" users' login information, so they won't make the login everytime they go the your website.
You can start checking for a valid session and at last case checking for their stored cookies.

Thanks gesf for your reply. There's one thing I still don't understand: is it possible to find out if cookies are enabled if I haven't set a session variable in a previous script?
Example: the user has not logged in yet, and if their session cookies in not enabled I would like to warn them that they need to enable it before they even try to log in. Do you know if that is possible?

Many thanks,
If you ment Cookies on client side: this will be another thing..
To check if users browser (client side) enabled cookies:

try setting a cookie and the reading from it... if you've done successfully: its pretty possible to say that they are activated..