Question

Instead of the file itself?

EDIT

Best with a demo in PHP?

Was it helpful?

Solution

<?php
// Get Headers
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,            'http://example.com/'); 
curl_setopt($ch, CURLOPT_HEADER,         true); 
curl_setopt($ch, CURLOPT_NOBODY,         true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT,        10); 
$response = curl_exec($ch); 

// Process Headers
$headerLines = explode("\r\n", $response);
foreach ($headerLines as $headerLine) {
    $headerLineParts = explode(': ', $headerLine);
    if (count($headerLineParts) >= 2) {
        $headers[$headerLineParts[0]] = $headerLineParts[1];
    }
}

echo $headers['Last-Modified'];
?>

OTHER TIPS

Yes. The "HEAD" method returns only the response headers and not the actual data.

You can use php's get_headers function

$a = get_headers('http://sstatic.net/so/img/logo.png');
print_r($a);

In your HTTP request you should add any of these header attributes, and you may receive an 304 (Last modified)

  1. If-Modified-Since
  2. If-None-Match
  3. If-Unmodified-Since

Andrei is correct, HEAD will only get the headers. My suggestion will return only the header and no body if the condictions are met. If the content has been updated the body will contain the new information.

You need to write some service to handle the http request and extract the last modified date for the requested file and return the date in response.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top