Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey. I got a directory listing script. The scripts work great but I want to keep track of how many times a page is accessed (hit) and output the directory in the order of most hits to least hits.

    I will need database support, so how can I modify the diccetory listing code to do this?

    If it helps heres my code.
    PHP Code:
    <?php
    $dir 
    "mytestdir/";

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
    if (
    $dh opendir($dir)) {
    while ((
    $file readdir($dh)) !== false) {
    print 
    "<a href=\"" $file "\">" $file "</a>";
    print 
    "<br>";
    }
    closedir($dh);
    }
    }
    ?>
    Thanks in advance

  2.  

  3. #2
    Member
    Join Date
    Jan 2005
    Posts
    97
    Member #
    8727
    Make a DB, have a single column table, hits INT. When you output the links the the dirlisting make them point back to the script itself e.g. "?file=foo.png". Then use an isset in the top of the dir list script to check if $_GET['file'] is set, and if set open up an SQL connection, SELECT the HITS thing, increment by one, then UPDATE it the the DB. header("Location: ") to the filename nominated in $_GET['file']. die();.

    Of course, you will need to do some file_exists() checking and build up the DB rows first, but it shouldnt be hard with a foreach loop.

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    So if I point the files like ?file=foo.png, when clicked, they will not go to the actual files address? I kinda wanted them to do that.

    Though thanks for the reply

  5. #4
    Member
    Join Date
    Jan 2005
    Posts
    97
    Member #
    8727
    Technically they will when the header() sends them there.

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Oh right you mean append the URL that the script gives to include the ?file=$filename

    I get ya

  7. #6
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Quote Originally Posted by bfsog
    ...and output the directory in the order of most hits to least hits.
    All this is clear now?
    S. Rosland

  8. #7
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Well I have not coded it up yet so your take on it is appreciated rosland.

  9. #8
    Member
    Join Date
    Jan 2005
    Posts
    97
    Member #
    8727
    For the most to least thingy (oops) just SELECT * FROM hits or whatever, turn the whole thing into an array, and asort() the array, then use a for() loop to output it.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:40 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com