note 55073 deleted from function.setcookie by nlopess
| From: | nlopess@php.net | Date: | Thu, 29 Sep 2005 08:32:38 +0000 |
| Subject: | note 55073 deleted from function.setcookie by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95963@lists.php.net to get a copy of this message | ||
Note Submitter: Kartik Borikar (kartikborikar at yahoo dot com)
----
The problem with setcookie() function is that you cannot test whether the cookies were set or not on
the same page. You need refresh the page to see if the cookie was saved.
There is another way of setting the cookie and then checking whether it was set or not set. Set
cookie top of a page and call an PHP file through HTML image tags. The PHP file then checks if the
cookie is set and then send error image or transparent image to the main page.
--- Main PHP Page ---
<?
setcookie ("test", "test" , time()+60*60, "/" );
?> <img src="cookiecheck.php">
--- cookiecheck.php code ---
<?
if(!isset($_COOKIE[test]))
{
readfile("error_text.gif");
}else
{
readfile("trans.gif");
}
?>
You can see this working at http://www.login.kkeim.com/