<html>
<! JustCookies.php                                            >
<! Chapter 12, Oracle Database XE PHP Web Programming         >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This demonstrates how to set a cookies and then obsolete   >
<! them.                                                      >
<head>
<title>
  Chapter 12 : JustCookies.php
</title>
<style type="text/css">
  div#centered {border:0;height:50%;top:25%;left:25%;width:50%;
                position:absolute;}
</style>
</head>
<body>
<?php
  // Check if a cookie is set and read its contents.
  if ((isset($_COOKIE['MyCookie1'])) && (isset($_COOKIE['MyCookie2'])))
  {
    print "MyCookie1 is set to: [".$_COOKIE['MyCookie1']."]<br>";
    print "MyCookie2 is set to: [".$_COOKIE['MyCookie2']."]<br>";
  }
  else
  {
    // Print the cookie is not set.
    print "MyCookie1, MyCookie2, or both are not set.<br>";

    // Set the cookies for a two minute life span.
    setcookie("MyCookie1", 'A simple string value 1', time() + 120, '/');
    setcookie("MyCookie2", 'A simple string value 2', time() + 120, '/');

  }

  // Print header.
  print "<hr>";
  print "Print all returned cookies:<br>";

  // Read all cookies available cookies sent in the URL.
  if (isset($_COOKIE))
    foreach ($_COOKIE as $name => $value)
      print "Cookie Name [$name]; cookie value [$value]<br>";

  // Expire the cookie by setting a negative life span.
  if (isset($_COOKIE['MyCookie2']))
    setcookie("MyCookie2", 'A simple string value 2', time() - 1, '/');

  // Print header.
  print "<hr>";
  print "Print all returned cookies after expiring [MyCookie2]:<br>";

  // Read all cookies available cookies sent in the URL.
  if (isset($_COOKIE))
    foreach ($_COOKIE as $name => $value)
      print "Cookie Name [$name]; cookie value [$value]<br>";
?>
</body>
</html>