Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Posts
    80

    Directory logging (pref php)

    I`ve a directory on my server where I want to log IP`s that try to access the directory, can be either flat file or SQL tables.

    Anyone know of one?

    Thanks

  2. #2
    Join Date
    Nov 2001
    Posts
    551
    I don't know of one, but there are two ways that come to mind.

    1. grep your access logs for that directory and parse the info. (downside: not real-time)

    2. have a mod_rewrite rule that shuttles everything to a script, that opens the file and sends it to the user (downside: large files might make it choke)

  3. #3
    Join Date
    Sep 2002
    Location
    Illinois
    Posts
    2,304
    PHP can't log access to the directory. Script works only when you call it.

    There are several ways you can do it

    1) Create index.php. In most cases that will cover 90% of the requests.

    2) Using Apache mod_rewrite you can redirect all request to the script
    Code:
    RewriteEngine On
    RewriteRule  /directory/(.+)     /directory/script.php  [L]
    Create a script that will get the IP address and write it into the file

    PHP Code:
    <?php

    $addr 
    $_SERVER["REMOTE_ADDR"];

    if(!
    $addr)
       die(
    "No IP, no access");

    // Make sure to give write permissions to the log file
    // Better to keep the file away from Apache access
    $fp fopen("ip.log""a");
    if(!
    $fp)
       die(
    "Could not open file");

    // Write IP and time accessed
    fwrite($fp$ip." - ".date("l dS of F Y h:i:s A"));

    fclose($fp);

    ?>
    You are done!

    Question? PM me.
    How's my programming? Call 1-800-DEV-NULL

  4. #4
    Join Date
    Apr 2004
    Posts
    80
    Thanks that worked perfectly

  5. #5
    Join Date
    Sep 2002
    Location
    Illinois
    Posts
    2,304
    Glad I helped.

    null
    How's my programming? Call 1-800-DEV-NULL

Posting Permissions

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