Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Unhappy read files, add and display results

    This is my first try ever on making PHP , so please be gentel

    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 )
    PHP Code:
    // 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($logsfilesize($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
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #2
    Regular Coder
    Join Date
    May 2006
    Posts
    101
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try this code in showcounter.php
    PHP Code:
    $file $_GET['page'].".log";
    // read .log files contents 
    $logs fopen($file,"r"
    $hits = @fread($logsfilesize($file)) or $hits=0
    fclose($logs); 

    // Print out Javascript code 
    echo " document.write($hits); "
    And load this script using
    Code:
    < script type="text/javascript" src="../componenter/pagecount/showcounter.php?page=index">

  • #3
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •