...

View Full Version : read files, add and display results



Jesper Møller
06-13-2006, 06:24 PM
This is my first try ever on making PHP , so please be gentel :o

I have a small PHP script on my site that count the visitors.
It works like this:
The "counter.php" makes a "pagename.log" file in a logs folder (The "logs" folder is placed beside the php script) for each page i want to make a count of.
when i want to make the count i place this on the site:
< script type="text/javascript" src="../componenter/pagecount/showcounter.php?page=index">< !--
//-->< /script>
then the script opens the "index.log" file int the "logs" folder read the number and rewrite it +1
this works fine :)

However i woud like to be able to read and display the numbers of wisitors, without that being count as a visit, and to make a total of the hits of difrent pages.
Like "index" + "page1" + "page2" has been wisit X-times ... "page1" + "page3" + "page4" has been wisit X-times ... and so on

so i have tryd looking at some phpscript i use that works, and tryd mergeing them to what i need. but it dont work. i realy hope someone can help mee :(

Her is a page where i try to use it http://www.jart.dk/jgom/test.html
(The 2 first numbers ar froem script that works)

And heres is the php i have tryd to make (Please be cind its my first php try ever :o )


// Print out Javascript code
echo "var pcount = new Array();\n";

// read logs folder directory contents
$dirHandle = opendir('./logs/');
while ($file = readdir($dirHandle)) {
if(!is_dir($file))
// set .log files id name
$id = $file
// read .log files contents
$logs = fopen($file,"r")
$hits = @fread($logs, filesize($file)) or $hits=0;
fclose($logs);
// Print out Javascript code
echo "pcount[$id]=$hits;\n";
}
closedir($dirHandle);

// Print out Javascript code
echo "
function pagecount_display(id)
{
document.write(pcount[id]);
}
";

exit();



Jesper

hope my bad enlighs skills are understandable :o

harsh789
06-14-2006, 06:57 PM
Try this code in showcounter.php

$file = $_GET['page'].".log";
// read .log files contents
$logs = fopen($file,"r")
$hits = @fread($logs, filesize($file)) or $hits=0;
fclose($logs);

// Print out Javascript code
echo " document.write($hits); ";


And load this script using

< script type="text/javascript" src="../componenter/pagecount/showcounter.php?page=index">

Jesper Møller
06-14-2006, 08:02 PM
Thanks... Ill try that

But wont
....ount/showcounter.php?page=index
only give me the result frome the index page ?
What i need is getting the result from multiple pages

Eg
Like "index" + "page1" + "page2" has been wisit X-times
page1" + "page3" + "page4" has been wisit X-times
... and so on



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum