Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> <?php ?> Unique Visitors Script, Flat file unique visitors script (no sessions)
Rating 1 V
matak
post Jul 30 2007, 05:38 AM
Post #1


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



This is really simple script. Well at least this part is, but it could be extendable. Only problem is that it's not really for massive websites with hundread of visitors a day, but rather for small ones. But it is a good script to figure out how to make a visitor counter script.

Anyway here's the snippet.

CODE
<?php
function getVisits($variable) {

    $visits = array();

    if ($handle = opendir('stats/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            array_push($visits, $file);
        }
    }
    closedir($handle);
    }
    $key = array_search($variable, $visits);
    
    if ($key !== FALSE) {
        
        echo "Posjeta do sada: ".count($visits);
        
    }
    elseif ($key === FALSE){
        $file = fopen("stats/".$variable, 'a');
        fwrite($file, $variable);
        fclose($file);
    
        getVisits($variable);
    }
}
?>


Just call it with getVisits($_SERVER['REMOTE_ADDR'])., and be sure to have that stats directory in same root as file in which script is executed.

Comments or improvments are welcome.
Go to the top of the page
 
+Quote Post
reconraiders
post Jul 30 2007, 07:27 AM
Post #2


Super Member
*********

Group: Members
Posts: 221
Joined: 6-June 07
Member No.: 44,288



Good work! Looks pretty good to me. I might use this but maybe use MySql instead of flat files. I just like SQL smile.gif
Go to the top of the page
 
+Quote Post
matak
post Jul 30 2007, 07:43 AM
Post #3


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



Ok, fast reply works again xd.gif

Yeah, mySQL is great, this is like i stated for small sites with less than 10(0) visitors a day smile.gif. I'm extending the script so it saves in directories based on a date value, and stuff like that, so that later i don't have like millions of files. biggrin.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Php Unique Hit Counter(29)
  2. Web Surfing- Script Needed(2)
  3. Import From Excel File Into Mysql Database(9)
  4. Delay X Seconds In Flash(1)
  5. Verifying Email Addresses(9)
  6. My Review Of Megaupload.com(25)
  7. How To Put Music In The Background Of A Powerpoint Presentation(10)
  8. Watermark Your Image With Simple Php Script(35)
  9. How To Open A .daa File(39)
  10. Read File (.txt) On Another Website Using Jsp?(3)
  11. Need To Shrink The File Size Of Web Image? - Photoshop Tricks(3)
  12. The Earth Is Really Flat(107)
  13. Background Image Swap Script(15)
  14. Php Downloads Script(4)
  15. Login Script For Vbulletin.(9)
  1. Make A Flat Based Shoutbox, With Auto Refresh.(6)
  2. Guessing Php Script(2)
  3. Free Software For File Recovery(6)
  4. Phpizabi Social Network Script(1)
  5. Php Guest Online Script(3)
  6. Redirecting Visitors To Different Page(8)
  7. How To Make Php Newsletter Script(3)
  8. File Sharing Hosts!(3)
  9. File Sharing Hosts!(0)
  10. Browser Compatibility Problem With Firefox - Javascript + Css(3)
  11. Seeking Help With Javascript(1)
  12. Top Web Attractions(1)
  13. How To Extract The Audio From Youtube Videos(2)


 



- Lo-Fi Version Time is now: 8th September 2008 - 01:49 AM