I am trying to create a php page that will do the following: “Create a document with a “nag” counter that reminds users to register for the site on the 3rd visit and not tell them to register if they have already registered. ” I need to do this with cookies since the users will not be logged in originally.
Here is what I am attempting to do:
Create a cookie called nag (value 1 for 1st visit) and a cookie called register ( value 0 for not registered).
When a user visits the site the first time, the cookies are created. Cookies are: Nag = 1 and Registered = 0.
On the 2nd visit, I want the nag cookie value to go to 2, and on the 3rd visit, I want the nag cookie value to get set back to 1 and echo a message telling the user “Please register.”
If the user registers, I want the nag cookie to get set to Zero and the registered cookie to get set to 1.
Here is my php document. I can’t seem to get this to work, but I have given it a lot of hard work so far. I am a php rookie. Can you help me?
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0
Strict//EN”
“
<html xmlns=”
<body>
<?php
$cookie_name_nag = “nag”;
$cookie_value_nag = “1”;
$cookie_name_registered = “registrated”;
$cookie_value_registered = “0”;
if(!isset($_COOKIE[“$cookie_name_nag”])) {
setcookie($cookie_value_nag, 1, time() + (86400 * 30), “/”); // 86400 = 1 day
}
if ($cookie_value_nag == 1){
setcookie($cookie_value_nag, 2, time() + (86400
}
if ($cookie_value_nag == 2){
echo “Please remember to register”;
}
if ($cookie_value_nag == 3){
setcookie($cookie_value_nag, 0, time() + (86400 * 30), “/”); // 86400 = 1 day
}
?>
<?php
if(!isset($_COOKIE[“$cookie_name_registered”])) {
setcookie($cookie_name_registered, 0, time() + (86400 * 30), “/”); // 86400 = 1 day
} else {
if ($cookie_value_registered == “1”)
echo “Thank you for being a member of Oglee!”;
}
?>
<!– Document heading –>
<head>
<title>Oglee</title>
<meta http-equiv=”content-type”
content=”text/html; charset=iso-8859-1″ />
</head>
<body>
<!– Table with heading in it –>
<table>
<tr>
<td><h1>Oglee Registration Form</h1></td>
</tr>
</table>
<!– Line to break the heading from the text fields –>
<hr />
<table>
<tr>
<td>
Thank you for visiting the Oglee Video Service registration page. As a registered user of Oglee, you will gain access to the following benefits:
</td>
</tr>
</table>
<table>
<tr>
<td>
<ul>
<li>Free movie streaming</li>
<li>No commercials</li>
<li>High Definition streams</li>
</ul>
</td>
</tr>
</table>
<table>
<tr>
<td>Username:</td>
<td>
<input type=”text” name=”username” maxlength=”40″ required/><br />
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<input type=”email” name=”email” maxlength=”40″ required/>
</td>
</tr>
</table>
<p><input type=”submit” value=”Submit” /></p>
</body>