note 11611 deleted from function.setcookie by vincent

From: Date: Fri, 12 Sep 2003 06:34:25 +0000
Subject: note 11611 deleted from function.setcookie by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-56309@lists.php.net to get a copy of this message
Note Submitter: pzijde@zs.nl ---- 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 ...

« previous php.notes (#56309) next »