phpaccount Posted August 18, 2013 Share Posted August 18, 2013 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 Quote Link to comment Share on other sites More sharing options...
rk8479 Posted August 18, 2013 Share Posted August 18, 2013 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 Quote Link to comment Share on other sites More sharing options...
phpaccount Posted August 19, 2013 Author Share Posted August 19, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.