Re: Not counting my own page visits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux