The cookie is not set. Refresh the screen to set the cookie. |
| The source of this page is: |
|---|
<?php
// The php code has to start at the very top of the page.
// Since I cannot echo any text until after I set the cookie,
// I will buffer text in the variable $html, then echo it to
// the screen after I set the cookie.
if ($myCookie=="") {
// The cookie is not set, ask the user to set the cookie.
$html="<p>The cookie is not set. Refresh the screen to set the cookie.</p>";
// I set the cookie with the value 1.
setcookie("myCookie",1);
} else {
$html="The value of the cookie is $myCookie. Let's try adding one to the cookie.
Press refresh.";
setcookie("myCookie",$myCookie+1);
}
// now that I have set the cookie, I can begin echoing HTML.
// I will print the HTML header, and put the value of $html into my header.
echo "<html><head><title>Sample 5.3 -- Test Cookie</title></head>";
echo "<table align=center><tr><td>".$html."</td></tr></table>";
?>
|
| Call this code with the link Sample 5.2 Back to Lesson 5 |