Re: Snarl, hiss, growl (frustration)

From: Date: Fri, 04 Jul 2003 16:37:22 +0000
Subject: Re: Snarl, hiss, growl (frustration)
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-154008@lists.php.net to get a copy of this message
No, because if i did that the counter would increment no matter what the IP address is. The way I have it the counter will only increment if it is a new ip address to the site. I just fixed it by switching $current++; to $current += 1; Apparently there is some small difference between the two. On Sat, 5 Jul 2003 00:42:59 +1000, "Tom Rogers" <trogers@kwikin.com> said: > Hi, > > Saturday, July 5, 2003, 12:33:25 AM, you wrote: > KB> Why does this not work? It is just a simple hit counter (hence the > KB> snarls, hissing, and growling). It logs the ips address but does not > KB> increment $current or log it. I do have counter.txt and ips.txt > chmod'd > KB> to 777. Ips.txt starts blank and counter.txt starts with just a 0 in > it. > > KB> <?php $counter = fopen('counter.txt', 'r'); > KB> $current = fread($counter, filesize('counter.txt')); > KB> fclose($counter); > > KB> $ip = getenv('REMOTE_ADDR'); > KB> $ipCheck = file('ips.txt'); > KB> if (!in_array($ip, $ipCheck)) { > KB> $ipAdd = fopen('ips.txt', 'a'); > KB> fwrite($ipAdd, "\n$ip"); > KB> fclose($ipAdd); > > KB> $current++; > KB> $counter = fopen('counter.txt', 'w'); > KB> fwrite($counter, $current); > KB> fclose($counter); > KB> } > > print $current; ?>> > KB> -- > KB> Kyle > > > maybe you need to end the if() statement before incrementing the > counter. > $ip = getenv('REMOTE_ADDR'); > $ipCheck = file('ips.txt'); > if (!in_array($ip, $ipCheck)) { > $ipAdd = fopen('ips.txt', 'a'); > fwrite($ipAdd, "\n$ip"); > fclose($ipAdd); > } > $current++; > $counter = fopen('counter.txt', 'w'); > fwrite($counter, $current); > fclose($counter); > print $current; ?> > > -- > regards, > Tom > > -- Kyle

« previous php.general (#154008) next »