Jump to content


Photo

PHP Counter


  • Please log in to reply
6 replies to this topic

#1 Xero

Xero

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Location:New York, USA
  • Interests:Anime, gaming, soccer, web design.

Posted 10 November 2004 - 09:04 PM

Can someone make me a PHP counter tutorial that when I visit it doesn't increase, and only goes up when a person visits the first page that they go to. I really need this, I'll mention you on my site for the help. Thanks.

#2 Nascaron

Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 15 November 2004 - 10:23 AM

One unique hits counter, coming up!

[EDIT]
Here you go:
<?
$database = "counter_db.txt";
$vis_ip = $_SERVER[\'REMOTE_ADDR\'];
$ip_list = file($database);
$visitors = count($ip_list) - 1;

if (in_array($vis_ip, $ip_list)) {
 echo ("$visitors");
}
else {
 $fp = fopen($database,"a");
 fwrite($fp, "\n$vis_ip");
 fclose($fp);
 $visitors++;
 echo $visitors;
}
?>

For instructions on how to use it:
http://toodesign.gax...ehitcounter.php
(I placed explaining notes in the code at the URL above. If you want to know what does what in the script, be sure to check that link out.)

Enjoy! (Any comments, suggestions or questions are welcome)
[/EDIT]

#3 Xero

Xero

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Location:New York, USA
  • Interests:Anime, gaming, soccer, web design.

Posted 15 November 2004 - 03:44 PM

Thats the only code I need, thanks.

#4 Nascaron

Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 15 November 2004 - 05:00 PM

You're welcome. Any feedback would be appreciated.

#5 Xero

Xero

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Location:New York, USA
  • Interests:Anime, gaming, soccer, web design.

Posted 20 November 2004 - 04:18 PM

I just got back to this, and I forgot to ask, where do I put my IP, lol. I'm a big PHP noob, so I really don't know anything :ph34r: .

#6 Nascaron

Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 20 November 2004 - 05:29 PM

You do not need to 'put your IP' anywhere. The script will use a database (counter_db.txt in this case) with IPs to determine if a visitor has visited the page already or is new. It then writes (if it is a new one) the IP to the database for further usage.

Just be sure you make an empty file with the name 'counter_db.txt', upload it to your website into the same directory as your page containing the script and finally CHMOD the 'counter_db.txt' file to 777 (read-write-execute permissions).

Then simply view the page containing the script and it should do all the work for you!

-Nascaron

#7 Xero

Xero

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Location:New York, USA
  • Interests:Anime, gaming, soccer, web design.

Posted 21 November 2004 - 05:30 PM

Oooh, gotcha. But how do I make it so it doesn't count my visits?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users