Check cookies with php
- June 6, 2006 by Emanuele Feronato
- Filed under Php, Tutorials | 7 Comments
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.
1 2 3 4 5 6 | <?php setcookie ('test', 'test', time() + 60); echo "value of \$test: $test<br>"; echo "value of \$_COOKIE[test]: ".$_COOKIE[test]."<br>"; echo "value of \$HTTP_COOKIE_VARS[test]: ".$HTTP_COOKIE_VARS[test]."<br>"; ?> |
7 Responses
Leave a Reply
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online
- Giochi casino


(10 votes, average: 3.40 out of 5)



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']
all this cookie talk has made me hungry