/    Sign up×
Community /Pin to ProfileBookmark

PHP Nag Counter Issue

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”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<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 *
30), “/”); // 86400 = 1 day

}
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>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 05.2016 — You cannot have [i]any[/i] output before the call to setcookie(), including text (or even just whitespace) before the opening <?php tag. So start the file with a <?php tag, do your cookie stuff (and anything else that sends headers, such as session_start()), [i]then[/i] you can start your HTML output.
Copy linkTweet thisAlerts:
@NogDogMar 05.2016 — PS: You probably would have a seen an error message to that effect if you had all error reporting turned on (or checked the php error log).
[code=php]
<?php
ini_set('display_errors', true); // set to false in production
error_reporting(E_ALL);
[/code]
×

Success!

Help @kristobal16 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...