How to get the last modified date of a URL in PHP

2 Answers

0 votes
$h = get_headers("http://www.php.net", 1);

if(!$h || strpos($h[0], '200') !== false)
    echo $h['Last-Modified'];

/*
run:

Fri, 10 Jun 2016 07:50:11 GMT

*/

 



answered Jun 10, 2016 by avibootz
0 votes
$curl = curl_init('http://example.com');

// don't the content, we need the headers
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// get the modified date
curl_setopt($curl, CURLOPT_FILETIME, true);

$result = curl_exec($curl);

if ($result === false) 
    die(curl_error($curl)); 

$tm = curl_getinfo($curl, CURLINFO_FILETIME);
if ($tm != -1) 
    echo date("d-m-Y H:i:s", $tm); 

/*
run:

09-08-2013 23:54:35

*/

 



answered Jun 10, 2016 by avibootz

Related questions

1 answer 140 views
1 answer 148 views
1 answer 190 views
1 answer 208 views
1 answer 214 views
1 answer 211 views
...