Return Header of external file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm working on an Ajax script, and the PHP script is supposed to read
the filemtime of the external text file, compare it to the cached
file, and either return a 200 or 304 header. But I've tried dozens of
variations, and still only get the default 200.

Here is the script I'm using:

$user = $_GET['user'];
$noupdate = false;

if ($user) {
  if (@fopen("/home/myacct/$user.txt", "r")) {
    $lastmod = filemtime("/home/myacct/$user.txt");
    $this_lastmod = gmdate('D, d M Y H:i:s', intval($lastmod)) . '

    $headers = apache_request_headers();
    if (isset($headers['If-Modified-Since']) && (strtotime($headers
['If-Modified-Since']) == $lastmod))
      $noupdate = true;

if ($noupdate) {
  header("HTTP/1.0 304 Not Modified");

else {
  header("HTTP/1.0 200 OK");
  header("Last-Modified: $this_lastmod");

I've ran several tests to make sure that $user exists correctly, and
it does make it to the line that defines $headers. The only line that
I'm not sure about is the if (isset($headers... line, because I
borrowed that from instead of writing it myself, and I'm not
entirely sure what the If-Modified-Since variable does.

Any advice would be greatly appreciated! TIA,


Re: Return Header of external file

Quoted text here. Click to load it

Hi Jason,

It looks like you need to debug the $headers variable to see what is
being supplied. Getting firebug for firefox will allow you to see the
request/response headers. Also, you can send the contents $headers
variable to your email using this:

mail('your@email', 'debug headers', print_r($headers, true));


Site Timeline