Test if COOKIE is available ...

A

Anonymous

Guest
Hi all

How can I test if COOKIES are available on the browser ?
 
You can set a cookie, then try and read it...

<?
//first, set a cookie..
setcookie("test","1",time()+60);
//then
if ($_COOKIE["test"] != "1") { //cookies are not working... }
?>

The original cookie is then deleted after 60 seconds...

Hope that helps you,

Andrew
 
You can't read a cookie that you've set on the same instance of the page. You'd have to set the cookie, send the user to another page (or the same page again), and then read the cookie.
 
oops, been a little while since I played with cookies - I tend to use sessions instead these day's


Andy
 
thanx to you both for the answers
so what are you saying is I make a page which loads twice
and in first time I set the cookie and in the second time I try to
read it , and if it works COOKIES are enable!

Actually I have a SPLASH screen for my web site which I want to
show it ONCE at all. so I used cookie to see whether is has been shown
or not.

The SLPASH screen and MAIN (HOME) page are both in my INDEX.php file.

any idea how to do that ?
 
Code:
//index.php
if (!$_COOKIE['seensplash'])
{
   header("Location: /setcookie.php");
   exit;
}

//setcookei.php
setcookie('seensplash', true);
header("Location: /index.php");

u need to be careful however...
if the browser has no-cookies option..
it will go recursive
 
u need to be careful however...
if the browser has no-cookies option..
it will go recursive

yes , and thats why I want to check COOKIES first before showing splash screen , so if browser doesnt support cookies or they have a firewall or something so I will skip showing the Splash Screen and go straight to the home page!

but its pretty hard to find out that before showing SPLASH SCREEN , becuase that the first page I have to show anyway!

or maybe I can load a page before SPLASH SCREEN to find out if I can use cookies or not! ;)

Thanx a lot for tip
 
Back
Top