on 5/31/00 11:24 PM, Vincent Danen wrote:
> Sorry, probably wrong list but... I need a little help with PHP. I'm
> trying to make a PHP-based counter for my web page but want it based on
> unique visits (not refreshes, etc.)
>
> I'm storing the IP address in the MySQL table and want to compare the
> current IP to the last IP address stored in the database, so this is what
> I'm currently using (but it doesn't work):
>
> $curip = getenv('REMOTE_ADDR');
> if ($ip != $curip) {
> $count = $count + 1;
> }
>
> But it increases on every refresh. I don't see a different comparison
> operator for strings (like in perl), otherwise I'd use "ne" instead of
> "!=". Does anyone know why this isn't working?
>
> Thanks in advance.
"!=" is right. try looking at the data to see what you've really got.
<?
$curip = getenv('REMOTE_ADDR');
if ($ip != $curip) {
$count = $count + 1;
}
echo '$ip= ' . $ip;
echo ' $curip= ' . $curip;
?>
also - do you really want to store all those ip addresses for a simple hit
counter? that table could get pretty big and you wouldn't count visitors who
come via proxy servers and gateways (everyone from AOL would count as one
hit) . I'd give the visitor a cookie and increment only if the cookie is not
present. I use this technique to keep people from voting twice in my poll.
the count is a little sloppy because lots of people turn cookies off but
most people leave cookies on and in fact have never heard of them.
cookies are easy:
// test for cookie
if (!$hit) {
//increment counter
$count++;
//set hit cookie
setcookie("hit","Been there!",time() +3600,"/"); /* expire in 1 hour */
}
Gavin