Forum Moderators: coopster

Message Too Old, No Replies

TRACKING/Logging scripting problem...

need some help here:)

         

sezampicika

7:31 am on Apr 7, 2004 (gmt 0)

10+ Year Member



I've found script that writes all visitors to a TXT file:

<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$user = $_SERVER['PHP_AUTH_USER'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$dtime = date('r');

if($ref == ""){
$ref = "None";
}
if($user == ""){
$user = "None";
}

$entry_line = "$dtime - IP: $ip ¦ URL: $uri ¦ Referrer: $ref

";
$fp = fopen("somefolder/sometextfile.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
?>

I now have problem... I want to see TOTAL number of visitors on the top... Can someone help? I think that is only one line of code but I don't know it:(
Please someone helo me...

Thank you very much.

barn_de

7:43 am on Apr 7, 2004 (gmt 0)

10+ Year Member



Hi sezampicika,

you're right about this one line :D
On Linux you can just count the lines in the file:

$iLines = `cat sometextfile.txt ¦ wc -l`;

if you have a windows system, i couldn't think of something with only one line of code. but i found smth what works.

$fp = fopen("sometextfile.txt", "r");
while (!feof($fp)) {
$sFile .= fgets($fp, 4096);
}
fclose($fp);

$aLines = explode("\n", $sFile);
echo count($aLines);

hope this helps

barn

sezampicika

7:52 am on Apr 7, 2004 (gmt 0)

10+ Year Member



Sorry... Can you please tell position where should I add that code?

Thanks

sezampicika

7:58 am on Apr 7, 2004 (gmt 0)

10+ Year Member



And... I want to SHOW this total number on mysite.com/log/index.txt ... Not on my main site...

thanks

barn_de

9:38 am on Apr 7, 2004 (gmt 0)

10+ Year Member



so you probably should write a report.php file or smth like this. and put it in a protected area.

and this file would execute the code i posted before.

btw does your script log every request? because then it wouldn't be visitors it would be requests. its not even PIs because hits from robots don't count as Pageimpressions.

barn

sezampicika

9:51 am on Apr 7, 2004 (gmt 0)

10+ Year Member



This will count every IP, (somethink like page views/hits)...

I need that text file is like:

TOTAL:
3213
visit1 ...
visit2
visit3...

Understand?

barn_de

9:52 am on Apr 8, 2004 (gmt 0)

10+ Year Member



but you don't do a lookup if the ip is already there right, you just add it to the file.

if so, i would call it hits instead of visitors.

if you really only store 1 ip / day, than you can call it visitors.

barn