Jump to content

PHP statistics script


1veedo

Recommended Posts

Ok, sense i'm hosting my website from my linux box, and thus no longer have cpanel and all the cool statistics, I'm writting my own data collection script that'll go into my index.php

<html><head></head><body>stats test

<?php
//log
$p = "test"; //$p is used in index to load the specified page
$browser = $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['REMOTE_ADDR'];
$lt = 1; //$lt = time() - $loaded;, time it took loading
//global
echo "1";
if(!($hits = implode('', file('hits')))) //load total hits, I'll get to monthly hits later
$hits = 1; //in case this script has never been run
else
$hits++;

if(!(implode('', file("time")))) //average laod time
$average = $lt;
echo"2";

$f1 = fopen("time", "a");
$f2 = fopen("hits", "a");

echo "3";

fwrite ($f2, $hits);

echo "4";

$hits--;
$newaverage = ($average * $hits + $lt) / ($hits + 1);

echo "5";

fwrite ($f1, $newaverage);

echo "6";

$f1 = fopen('/log/log.htm', 'a'); //global access log

fwrite ($f1, .$ip." got ".$p." using ".$browser." in ".$lt."<br>");

$f2 = fopen('/log/'.$ip, 'a')

fwrite ($f2, $p.", ".$browser.", ".$lt.":  ".gmdate('l, m-d, G:i'))

echo "7";
//$f1 = fopen('/log/'.$ip.".average", 'a')...eventually


//for current page stats, same script as global
if(!($hits = implode('', file('hits'.$p)))) 
$hits = 1; 
else
$hits++;

if(!(implode('', file("time")))){
$average = $lt;}
echo "8";
$f1 = fopen("time".$p, "a");
$f2 = fopen("hits".$p, "a");
echo "9";
fwrite ($f2, $hits);
echo "a";
$newaverage = ($average * $hits + $lt) / ($hits + 1);

fwrite ($f1, $newaverage);
echo "done";
?>

</body>
</html>

The problem is that not only does it not display all my 123...9adone, it does not write anyhting to a file. The script is currently in /run.php

 

I have no idea what's wrong.

 

On top of that, it's not even done. I need to somehow figure out how to tell what OS my users are running as well as where they were refered from. (I'd also like to get country too, but I figure there's no easy way to find out what nation they're from)

 

Of course, I'll need to eventually exclude my IP from the global statics but that'll come later.

 

So, two things:

1 Script does not run

2 How do I gather users' OS and referal.

 

:)

 

Oh, sry for not having my script commented. I'll get to that right away.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • 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.