Jump to content

Unique Hit Counter


JesseToxik

Recommended Posts

<?php$filename = "hits.txt";if (!file_exists($filename)){// hits.txt doesn't exist, let's try to create it.$fd = fopen($filename, "w+");fclose($fd);}$file = file($filename);$file = array_unique($file);$hits = count($file);// Print out the number of unique visitors we have had.echo $hits;$fd = fopen($filename, "r");$fstring = fread($fd, filesize($filename));fclose($fd);$fd = fopen($filename, "w");$fcounted = $fstring . "" . $_SERVER["REMOTE_ADDR"];$fout = fwrite($fd, $fcounted);fclose($fd);?> am using a hit counter script. It records ip address in a text file. Problem is it records the same ip over and over. How can I make it record the ip one time and one time only?

Link to comment
Share on other sites

Maybe not post on Android? So your posts are clearer? Anyhow, there are 2 options, as above use a database, the best and easiest way. Or you could store the IP on a new line in a text file, everytime someone visits your site loop through the file and check if the IP is in there if it is don't add it, else do add it, then just count the lines of the text file.

Link to comment
Share on other sites

And cushion for comfort...

 

There are plenty of tutorials on this... You can either store it in a database (which would make the most sense) or store it in a file. If you store it in a file, you could serialize or JSON encode an array and then decode it for full functionality. You can also store each entry on a new line. Whichever suits your need.

 

Get creative, search the webs. Dont ask us to do your stuff for you.

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.