Setting and Printing a Cookie Value : _COOKIE « Cookie Session « PHP






Setting and Printing a Cookie Value

 
<?php
 setcookie( "vegetable", "artichoke", time()+3600, "/","java2s.com", 0 );
 ?>
 <html>
 <head>
 <title>Setting and Printing a Cookie Value</title>
 </head>
 <body>
 <?php
 if ( isset( $_COOKIE['vegetable'] ) ) {
     print "<p>Hello again, your chosen vegetable is ";
     print "{$_COOKIE['vegetable']}</p>";
 } else {
     print "<p>Hello you. This may be your first visit</p>";
 }
 ?>
 </body>
 </html>
  
  








Related examples in the same category

1.Checking for Cookie Support from PHP
2.Get Cookie Data
3.Reading a cookie value
4.Printing a cookie value
5.Still Logged In with cookie
6.Reading all cookie values