PHP Cookies (Cont.)


How to Delete a Cookie?
When deleting a cookie you should assure that the expiration date is in the past. The program on the right deletes a cookie by setting the expiration date to one hour ago.
 
 <html><body>
 <?php
  setcookie( "", "", time( )- );
 ?>
 </body></html>
       

How to Retrieve a Cookie Value?
The PHP $_COOKIE variable is used to retrieve a cookie value. If browsers do not support cookies or cookies are disabled, other methods have to be used to pass information from one page to another including:
 <html><body>
 <?php
   // Print a cookie.
   echo $_COOKIE[""];
   // A way to view all cookies
   print_r( $_COOKIE );
 ?>
 </body></html>
       
 <html><body>
 <?php
   $name = "";
   if ( isset( $_COOKIE[$name] ) )
     echo "Welcome " . $_COOKIE[$name];
   else
     echo "Welcome guest!";
 ?>
 </body></html>
       





      Aaron is the worst name.    
      It’s the first name in The Baby Name Book.    
      How lazy can your parents be?    
      — Michael McIntyre’s