PHP Text and File based Hit Counter: Total, and all today.

  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post May 3rd, 2005, 11:16 pm

Will anyone be as so kind and supply me with a PHP script that counts unique visitors in total, but also showing how many there have been for that day?

I would like the I.P. addresses to be stored in a text file, but disposes of the I.P. address when the person leaves...

Thanks in Advance! :)
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 3rd, 2005, 11:16 pm

  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post May 4th, 2005, 2:47 am

No one can help?
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • lioness
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jun 23, 2004
  • Posts: 1615
  • Loc: Boston MA
  • Status: Offline

Post May 4th, 2005, 7:26 am

Funny_Fuzz - some words of advice.

1. Please be patient. You posted this request at 1:17AM my time, and as I am on the East Coast here in the states, I reckon most of Ozzu (US)will be in bed :wink:

2. This is a general observation regarding your posts - any help or advice you get on here is from people taking time out of their day, unpaid, to help other posters like yourself in your web-related questions. The tone of several of your requests has often been blunt or bordering agressive - you are more likely to get a quicker response if you seem to come across more pleasant and grateful.

3. Your request is something which has been asked - in some format - before on many forums and I am sure with a little effort you could find multiple solutions already on the internet.

:idea: http://www.google.com
:idea: http://www.ozzu.com/search.php

Finally, good luck in finding what you are after. 8)
  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Joined: Apr 07, 2004
  • Posts: 366
  • Loc: Riverside, CA
  • Status: Offline

Post May 4th, 2005, 9:52 am

I am at school right now, so I can supply you anything, but I will say this:

You can't dispose the IP's. You need to have them in a collection file so you can check each visitor, and see if their IP is logged, if it is, they have been there before, do you don't count the visit. If its not logged, the person has never been there so you increase the counter, and log the IP. Understand? With out an IP log, there is now way of determining a first time visit, from a re-visit.
http://www.koolzone.net
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post May 5th, 2005, 3:02 am

Well I don't know what I was talking about when I said about the I.P. disposal. Well, I've had a look at all of the Ozzu posts on this website about "Hit Counters" and "PHP Text Hit Counters" etc. But none of them did one of the things I asked for: Displaying the amount of unique visitors who visited, for the day.
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • lioness
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jun 23, 2004
  • Posts: 1615
  • Loc: Boston MA
  • Status: Offline

Post May 5th, 2005, 6:15 am

Funny_Fuzz wrote:
Well I don't know what I was talking about when I said about the I.P. disposal. Well, I've had a look at all of the Ozzu posts on this website about "Hit Counters" and "PHP Text Hit Counters" etc. But none of them did one of the things I asked for: Displaying the amount of unique visitors who visited, for the day.


So what about...

http://www.ozzu.com/ftopic37529.html 'Unique hit counter'
or
http://www.ozzu.com/ftopic1766.html

:?:
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post May 6th, 2005, 1:56 am

here is the class
PHP Code: [ Download ] [ Select ]
 
class IpLog{
 
   private $vIp;
 
   private $fName;
 
   private $today;
 
   private $isUnique;
 
   private $output;
 
   private $added;
 
   private $cr;
 
   
 
   /**
 
    * visitor::__construct()
 
    *
 
    * @param mixed $ip
 
    * @return void
 
    **/
 
   public function __construct($ip = -1){
 
      $this->cr      = "\r\n";
 
      $this->isUnique = false;
 
      $this->added   = false;
 
      $this->fName   = "ipLog.txt";
 
      $this->today   = date("Y") ."/" .  date("m") . "/" . date("d");
 
      if ($ip != -1){
 
         $this->vIp     = $ip;
 
          $this->addIp();
 
      }
 
   }
 
   
 
   /**
 
    * visitor::addIp()
 
    * add the ip address to the file if it is unique to the day
 
    * @return void
 
    **/
 
   private function addIp(){
 
      $fileArray = file($this->fName);
 
      if (count($fileArray) > 0) {
 
         $newString = $this->vIp . ";" . $this->today . $this->cr;
 
         if (!in_array($newString,$fileArray)){
 
            $this->output  = $this->vIp . ";" . $this->today . $this->cr;
 
            echo $this->isUnique    = true;
 
         }
 
      }else{
 
         $this->isUnique = true;
 
         $this->output  = $this->vIp . ";" . $this->today . $this->cr;
 
      }
 
      if ($this->isUnique) {
 
          $this->writeIp();
 
         $this->added   = true;
 
      }else{
 
         $this->added   = false;
 
      }
 
   }
 
   
 
   /**
 
    * visitor::writeIp()
 
    * write the ip address to the file
 
    * @return boolean
 
    **/
 
   private function writeIp(){
 
      $fh = fopen($this->fName,"a+");
 
      fwrite($fh,$this->output);
 
      fclose($fh);
 
      $this->output = "";
 
   }
 
   
 
   public function displayAll(){
 
      $fileArray     = file($this->fName);
 
      for ($i = 0; $i < count($fileArray); $i++){
 
         $dataArray     = explode(";",$fileArray[$i]);
 
         $this->output .= $dataArray[0] . " - " . $dataArray[1] . "<br />";
 
      }
 
   }
 
   
 
   public function displayGroup($date){
 
      $fileArray     = file($this->fName);
 
      for ($i = 0; $i < count($fileArray); $i++){
 
         $dataArray = explode(";",$fileArray[$i]);
 
         if (ereg($date,$dataArray[1])) {
 
            $this->output .= $dataArray[0] . " - " . $dataArray[1] . "<br />";
 
         }
 
      }
 
   }
 
   
 
   public function getOutput(){
 
      return $this->output;
 
   }
 
}
 
 
  1.  
  2. class IpLog{
  3.  
  4.    private $vIp;
  5.  
  6.    private $fName;
  7.  
  8.    private $today;
  9.  
  10.    private $isUnique;
  11.  
  12.    private $output;
  13.  
  14.    private $added;
  15.  
  16.    private $cr;
  17.  
  18.    
  19.  
  20.    /**
  21.  
  22.     * visitor::__construct()
  23.  
  24.     *
  25.  
  26.     * @param mixed $ip
  27.  
  28.     * @return void
  29.  
  30.     **/
  31.  
  32.    public function __construct($ip = -1){
  33.  
  34.       $this->cr      = "\r\n";
  35.  
  36.       $this->isUnique = false;
  37.  
  38.       $this->added   = false;
  39.  
  40.       $this->fName   = "ipLog.txt";
  41.  
  42.       $this->today   = date("Y") ."/" .  date("m") . "/" . date("d");
  43.  
  44.       if ($ip != -1){
  45.  
  46.          $this->vIp     = $ip;
  47.  
  48.           $this->addIp();
  49.  
  50.       }
  51.  
  52.    }
  53.  
  54.    
  55.  
  56.    /**
  57.  
  58.     * visitor::addIp()
  59.  
  60.     * add the ip address to the file if it is unique to the day
  61.  
  62.     * @return void
  63.  
  64.     **/
  65.  
  66.    private function addIp(){
  67.  
  68.       $fileArray = file($this->fName);
  69.  
  70.       if (count($fileArray) > 0) {
  71.  
  72.          $newString = $this->vIp . ";" . $this->today . $this->cr;
  73.  
  74.          if (!in_array($newString,$fileArray)){
  75.  
  76.             $this->output  = $this->vIp . ";" . $this->today . $this->cr;
  77.  
  78.             echo $this->isUnique    = true;
  79.  
  80.          }
  81.  
  82.       }else{
  83.  
  84.          $this->isUnique = true;
  85.  
  86.          $this->output  = $this->vIp . ";" . $this->today . $this->cr;
  87.  
  88.       }
  89.  
  90.       if ($this->isUnique) {
  91.  
  92.           $this->writeIp();
  93.  
  94.          $this->added   = true;
  95.  
  96.       }else{
  97.  
  98.          $this->added   = false;
  99.  
  100.       }
  101.  
  102.    }
  103.  
  104.    
  105.  
  106.    /**
  107.  
  108.     * visitor::writeIp()
  109.  
  110.     * write the ip address to the file
  111.  
  112.     * @return boolean
  113.  
  114.     **/
  115.  
  116.    private function writeIp(){
  117.  
  118.       $fh = fopen($this->fName,"a+");
  119.  
  120.       fwrite($fh,$this->output);
  121.  
  122.       fclose($fh);
  123.  
  124.       $this->output = "";
  125.  
  126.    }
  127.  
  128.    
  129.  
  130.    public function displayAll(){
  131.  
  132.       $fileArray     = file($this->fName);
  133.  
  134.       for ($i = 0; $i < count($fileArray); $i++){
  135.  
  136.          $dataArray     = explode(";",$fileArray[$i]);
  137.  
  138.          $this->output .= $dataArray[0] . " - " . $dataArray[1] . "<br />";
  139.  
  140.       }
  141.  
  142.    }
  143.  
  144.    
  145.  
  146.    public function displayGroup($date){
  147.  
  148.       $fileArray     = file($this->fName);
  149.  
  150.       for ($i = 0; $i < count($fileArray); $i++){
  151.  
  152.          $dataArray = explode(";",$fileArray[$i]);
  153.  
  154.          if (ereg($date,$dataArray[1])) {
  155.  
  156.             $this->output .= $dataArray[0] . " - " . $dataArray[1] . "<br />";
  157.  
  158.          }
  159.  
  160.       }
  161.  
  162.    }
  163.  
  164.    
  165.  
  166.    public function getOutput(){
  167.  
  168.       return $this->output;
  169.  
  170.    }
  171.  
  172. }
  173.  
  174.  


Here is the usage
PHP Code: [ Download ] [ Select ]
 
include_once("ipLog.class.php");
 
$ip      = "196.38.89.58";
 
$oIp  = new IpLog($ip);
 
//$oIp->displayAll();
 
$oIp->displayGroup("2005/05/06");
 
echo $oIp->getOutput();
 
 
  1.  
  2. include_once("ipLog.class.php");
  3.  
  4. $ip      = "196.38.89.58";
  5.  
  6. $oIp  = new IpLog($ip);
  7.  
  8. //$oIp->displayAll();
  9.  
  10. $oIp->displayGroup("2005/05/06");
  11.  
  12. echo $oIp->getOutput();
  13.  
  14.  


make sure you include the class file above
My Software Development Company
Music I have recorded (fixed now :))
Image
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post May 6th, 2005, 2:58 am

Lionking, the links don't get me the things I'm quite after...
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post May 6th, 2005, 3:53 am

Does it work?
My Software Development Company
Music I have recorded (fixed now :))
Image
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post May 8th, 2005, 3:48 am

Not quite. I don't know how to get it working, what to call them... etc.
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post May 8th, 2005, 10:37 pm

HUH??
My Software Development Company
Music I have recorded (fixed now :))
Image
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post May 9th, 2005, 12:07 am

Ok. I'll explain it in more detail. I don't know where to put the first lot of code, and what to call it. I also don't know what to do with the second lot of code...
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post May 9th, 2005, 1:08 am

ok the first lot of code is the CLASS file so store it in a PHP file called ipLog.class.php.

The next lot of code is an example of how to use it.

To add an IP address for the day
PHP Code: [ Download ] [ Select ]
 
include_once("ipLog.class.php");
 
$ip        = "196.38.89.58";
 
$oIp    = new IpLog($ip);
 
 
  1.  
  2. include_once("ipLog.class.php");
  3.  
  4. $ip        = "196.38.89.58";
  5.  
  6. $oIp    = new IpLog($ip);
  7.  
  8.  


To view the entries
PHP Code: [ Download ] [ Select ]
 
include_once("ipLog.class.php");
 
$oIp = new IpLog();
 
$oIp->displayAll();  // display all the antries
 
$oIp->displayGroup("2005/05/06");  // display the entries for a specific date
 
echo $oIp->getOutput();
 
 
  1.  
  2. include_once("ipLog.class.php");
  3.  
  4. $oIp = new IpLog();
  5.  
  6. $oIp->displayAll();  // display all the antries
  7.  
  8. $oIp->displayGroup("2005/05/06");  // display the entries for a specific date
  9.  
  10. echo $oIp->getOutput();
  11.  
  12.  


Make sense?
My Software Development Company
Music I have recorded (fixed now :))
Image
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post May 9th, 2005, 2:02 am

Rabid Dog wrote:
Make sence?


Much better! Thanks
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Joined: Dec 30, 2003
  • Posts: 222
  • Status: Offline

Post May 9th, 2005, 6:40 am

Don't forget to replace "196.38.89.58" with $_SERVER['REMOTE_ADDR'] ;)
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 9th, 2005, 6:40 am

Post Information

  • Total Posts in this topic: 57 posts
  • Users browsing this forum: No registered users and 182 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.