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
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 :)

Link to comment
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 :)

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.