Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7489781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:22:21+00:00 2026-05-29T15:22:21+00:00

I want to log access to any files in the /files folder, so I

  • 0

I want to log access to any files in the /files folder, so I can process it with PHP to generate some statistics.

I don’t want to write a custom PHP handler called via RewriteRule because I don’t want to have to deal with status codes, MIME-types and caching headers, and file locking issues.

I don’t have access to the server configuration, so I can’t use CustomLog (I do have access to .htacess).

I can’t use X-Sendfile because it’s not enabled.

I don’t have access to the access.log.


Looking for an authorative answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:22:22+00:00Added an answer on May 29, 2026 at 3:22 pm

    I’ve tried a great many things and there seems to be no easy solution.

    My solution uses the Location header trick proposed by @yes123 but I’ve tweaked it to match my preferences.

    The links to the files are kept intact, so it’s still: /files/path/to/my/file.abc
    I have a RewriteRule:

    RewriteRule ^files/(.*) path/to/tracker.php?path=/$1

    Then in the file I issue a Location header by adding ?track=no to the URL and an exception to the earlier RewriteRule:

    RewriteCond %{QUERY_STRING} !(&|^)track=no(&|$)

    I’ve added one more optimization. I’ve enabled E-Tags so if the client send an E-Tag header, see if it matches the file and return a 304 Not Modified instead of a Location.

    $fs = stat($document_root . $path);
    $apache_etag = calculate_apache_etag($fs);
    if ((isset($_SERVER["HTTP_IF_MATCH"]) && etag_within_range($_SERVER["HTTP_IF_MATCH"], $apache_etag))
        || (isset($_SERVER["HTTP_IF_NONE_MATCH"]) && etag_within_range($_SERVER["HTTP_IF_NONE_MATCH"], $apache_etag))
    ) {
        header("ETag: " . $apache_etag, true, 304);
        exit;
    }
    
    function etag_within_range($etag1, $etag2) {
        list($size1, $mtime1) = explode("-", $etag1);
        list($size2, $mtime2) = explode("-", $etag2);
        $mtime1 = floor(hexdec($mtime1) / 1000000);
        $mtime2 = floor(hexdec($mtime2) / 1000000);
        return $mtime1 === $mtime2 && $size1 === $size2;
    }
    

    And implementation for calculate_apache_etag can be found here: How do you make an etag that matches Apache?

    etag_withing_range solves the issue of comparing against a higher precision mtime in Apache.


    Notes on solutions that didn’t work

    virtual

    Test script:

    var_dump(apache_response_headers());
    virtual("/path/to/image.jpg");
    var_dump(apache_response_headers());
    

    Outputs:

    array(1) { ["X-Powered-By"]=> string(10) "PHP/5.2.11" }
    [[binary junk]]
    array(5) { ["X-Powered-By"]=> string(10) "PHP/5.2.11" ["Keep-Alive"]=> string(18) "timeout=5, max=100" ["Connection"]=> string(10) "Keep-Alive" ["Transfer-Encoding"]=> string(7) "chunked" ["Content-Type"]=> string(9) "text/html" }
    

    Content-Type: text/html reaaaaalllly? 🙁

    Perhaps PHP5.3’s header_remove function can solve this? I haven’t tried.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to log/write all Javascript errors to a text file whenever an error
I want to log some seemingly random errors I'm getting in a Delphi written
I have a php script that steps through a folder containing tab delimited files,
i want to derive from std::exception to add specific information to my log files,
I want to create a batch file to clear my Apache error log files,
I have all my Apache access log files as access.log, access.log.1 access.log.1.gz etc... What
i want log linenumber to my log file, using log4net.the config details of log4net
I want to log all toasts events in android ics (4.0.3), but I was
I want to log my log strings to a file. I implemented the following
i want to log messages from multiple classes. the problem is that currently i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.