Check cookies with php
Today, an interesting script to check cookies with php. I had to used it because a bad configuration on the server turned off cookie settings, and I have on my server various shopping cart using cookies.
You may get different results according to your register_globals settings.
Remember to reload the script to have the correct results as cookie variables become available on the next page you have declared them.
PHP:
Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
Tell me what do you think about this post. I'll write better and better entries.
6 Responses to “Check cookies with php”
Leave a Reply

You cant use php to do a cookies enable checking. In the initial stage before logging in the member page, you can do a redirect on the script to check if the client browser is cookie enable, but what if the user turn if the cookie half way browsing through your website?
The best way is to use javascript to check, because it’s always client-side script and you don’t need to reload the php page.
I strongly disagree with the Javascript solution. Lots of users turn off Javascript, so you may not get a reliable answer, whereas a server-side solution is sure to be executed.
The correct solution would be the first check to make sure the user has Javascript enabled and then check to make sure that cookies are enabled. I would agree with Bryansu that using a client side script rather then a server side script would make more sense and be more reliable.
Also i just wanted to say a really easy way to check cookies is with javascripts DOM
if (!navigator.cookieEnabled) {
document.write(”No Cookies”);
}else{
document.write(”Cookies Ok”);
}
Don’t you have to say:
$_COOKIE['test']
instead of:
$_COOKIE[test]
I use a lot of PHP and that’s always how I’ve done it.
Yes, it must be $_COOKIE['test']