Re: [PHP] Not counting my own page visits

[email protected] (David Robley)
Newsgroups php.general
Message-ID <[email protected]>
Angela Barone wrote:

> On Mar 4, 2013, at 11:33 AM, Ashley Sheridan wrote:
>> You can manually write a cookie on your machine, or use a special script
>> that only you visit that contains a setcookie() call (it only need be set
>> once). From there on, you can check the $_COOKIES super global for the
>> presence of your cookie.
> 
> I don't know why, but I can't get cookies to work.  Here's a script I'm
> calling from my browser:
> 
> <?php
>     $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ?
>     $_SERVER['HTTP_HOST'] : false;
> $cookie = setcookie('test2', '123' , time()+60*60*24*30, '/', $domain);
> ?>
> 
> <!DOCTYPE html>
> <html lang="en">
> <head>
> <meta charset="utf-8" />
> <title>Test Page</title>
> </head>
> <body>
> <?php echo 'Cookie is: '.$_COOKIE[$cookie]."<br>"; ?>
> <?php echo 'Domain is: '.$domain."<br>"; ?>
> </body>
> </html>
> 
> The domain is being displayed but the cookie is not.  There's no cookie in
> the browser prefs, either.  What am I doing wrong?
> 
> Angela

Misunderstanding what $cookie contains? It is a boolean, i.e. it will be 
true or false depending on whether the cookie was set or not. To echo the 
contents of a cookie, you need to use the cookie name, viz

<?php echo 'Cookie is: '.$_COOKIE['test2']."<br>"; ?>

-- 
Cheers
David Robley

Oxymoron: Sisterly Love.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.