Forum Moderators: coopster

Message Too Old, No Replies

Does anyone see my error?

Can't trace something here.

         

SaminOz

1:50 am on Jun 7, 2009 (gmt 0)

10+ Year Member



Hi everyone,
Just wondering if anyone can see a glaring hole in my logic here - as I can't. The result at the moment is always "1" - no matter how I shift things aroudn.

I am working through a tutorial to set a cookie that shows how many times a page has been visited. Here is the code that is before the <html> tag.

<?php
function visitNumber($pageVisits) {
echo '<h1>You have viewed this page '.$pageVisits.' time(s) </h1>';
}
$pageVisits = 1;
if(isset($_COOKIE['cookieVisits'])) {
$pageVisits = $_COOKIE['cookieVisits'] + 1;
}
setcookie('cookieVisits', '$pageVisits', time() +60*60*24*365);
?>

And here is the display in the <body>.

<?php
echo visitNumber($pageVisits);
?>

Habtom

4:42 am on Jun 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change:

setcookie('cookieVisits', '$pageVisits', time() +60*60*24*365);

to

setcookie('cookieVisits', $pageVisits, time() +60*60*24*365);

SaminOz

5:02 am on Jun 7, 2009 (gmt 0)

10+ Year Member



duh! thanks :)