note 11611 added to setcookie
| From: | pzijde at zs dot nl | Date: | Tue, 27 Feb 2001 13:51:06 +0000 |
| Subject: | note 11611 added to setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11635@lists.php.net to get a copy of this message | ||
Here is a solution to set and check a cookie within 1 document:
<!-- img_stat.php -->
<?php
SetCookie ("test_id","Test",0,"/",".foo.com",0);
Header("Location: /img_stat2.php")
?>
<!-- img_stat2.php -->
<?php
header ("Content-type: image/gif");
$im = @ImageCreate (100, 50) or die ("not supported ...");
if ("$test_id" == "Test") {
# The cookie is set, do your action
$background_color = ImageColorAllocate ($im, 0, 0, 0);
} else {
# Cookie is not set, do your action
$background_color = ImageColorAllocate ($im, 255, 255, 0);
}
ImageGif ($im);
?>
<!-- HTML document -->
<img src="img_stat.php">
This example displays a black image when the cookie is accepted, otherwise displays a yellow image.
But of course you can put every code you want.
NOTE: The cookie is not available in the HTML document during the first load, only in the second
image file!!
I hope this will help ...
http://www.php.net/manual/en/function.setcookie.php