Jump to content

accurate php hit/visitor counter


phpaccount

Recommended Posts

I currently have this

<?php
/* counter */
//opens countlog.txt to read the number of hits$datei = 
fopen("countlog.txt","r");$count = 
fgets($datei,1000);fclose($datei);$count=$count + 1 ;
// opens countlog.txt to change new hit number$datei = 
fopen("countlog.txt","w");fwrite($datei, $count);fclose($datei);
?>

But it counts mostly 3 or 4 times for 1 visit, I read somewhere broken images are the causes(Can't fix it, im new to this).

So how do I make a  simple  counter that counts the visitors of your website?

Not with a visual element, but just so it stores visits in countlog.txt

Link to comment
https://forums.phpfreaks.com/topic/281304-accurate-php-hitvisitor-counter/
Share on other sites

Hi, it mainly depends on what aspect of your visitors you want to track, you could track them by thier IP address and store that in a database or a textfile (i would recommending ditching the text file idea as its not index-able like a DB is).

 

you could also track them by the device they use, you could use the user agent to get its raw form or use a third party library such as Detector.

 

you could also track what pages the IP visits by using $_SERVER['REMOTE_ADDR'] to gain the IP and then use $_SERVER['REQUEST_URI'] to gain the visitors page they visited

 

again, this information is most likely inefficient in a text file, once you get the values then just upload them to a DB then you could select where the visitor from a selected IP has been on your site :)

Hi, it mainly depends on what aspect of your visitors you want to track, you could track them by thier IP address and store that in a database or a textfile (i would recommending ditching the text file idea as its not index-able like a DB is).

 

you could also track them by the device they use, you could use the user agent to get its raw form or use a third party library such as Detector.

 

you could also track what pages the IP visits by using $_SERVER['REMOTE_ADDR'] to gain the IP and then use $_SERVER['REQUEST_URI'] to gain the visitors page they visited

 

again, this information is most likely inefficient in a text file, once you get the values then just upload them to a DB then you could select where the visitor from a selected IP has been on your site :)

I just want a simple visit counter, I have almost no experience in php so I don't know where to start.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.