A stats script for my site.

Discussion in 'PHP' started by asgsoft, May 7, 2006.

  1. #1
    I use this script for showing stats on my site, although some of it doesn't worl. The only section that doesn't work is showing todays unique viewers.

    Here is what I use:

    
    <?php
    // Our log file;
    $counter = "stats.txt";
    
    // Date logging;
    $today = getdate();
    $month = $today[month];
    $mday = $today[mday];
    $year = $today[year];
    $current_date = $mday . $month . $year;
    
    
    // Log visit;
    $fp = fopen($counter, "a");
    $line = $REMOTE_ADDR . "|" . $mday . $month . $year . "\n";
    $size = strlen($line);
    fputs($fp, $line, $size);
    fclose($fp);
    
    // Read log file into array;
    $contents = file($counter);
    
    // Total hits;
    $total_hits = sizeof($contents);
    
    // Total hosts;
    $total_hosts = array();
    for ($i=0;$i<sizeof($contents);$i++) {
    	$entry = explode("|", $contents[$i]);
    	array_push($total_hosts, $entry[0]);
    }
    $total_hosts_size = sizeof(array_unique($total_hosts));
    
    // Daily hits;
    $daily_hits = array();
    for ($i=0;$i<sizeof($contents);$i++) {
    	$entry = explode("|", $contents[$i]);
    	if ($current_date == chop($entry[1])) {
    		array_push($daily_hits, $entry[0]);
    	}
    }
    $daily_hits_size = sizeof($daily_hits);
    
    // Daily hosts;
    $daily_hosts = array();
    for ($i=0;$i<sizeof($contents);$i++) {
    	$entry = explode("|", $contents[$i]);
    	if ($current_date == chop($entry[1])) {
    		array_push($daily_hosts, $entry[0]);
    	}
    }
    $daily_hosts_size = sizeof(array_unique($daily_hosts));
    
    ?>
    <?php
    echo"<tr> 
                          <td width='75%'>Todays Unique:</td>
                          <td width='25%' bgcolor='#F4F4F4'>$daily_hosts_size</td>
                        </tr>
                        <tr> 
                          <td>Todays Views:</td>
                          <td bgcolor='#F4F4F4'>$daily_hits_size</td>
    
                        </tr>
                        <tr> 
                          <td>Total Unique:</td>
                          <td bgcolor='#F4F4F4'>$total_hosts_size</td>
                        </tr>";
    ?>
    
    
    PHP:
    It all works except todays unique.
     
    asgsoft, May 7, 2006 IP
  2. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    why dont you try using google analytics or something like that?
     
    undir, Sep 4, 2007 IP