基于带有卷曲的标头提取 url


Extracting url based on headers with curl

我想给一个带卷曲的网址。并根据其标头属性 Expires 获取它。

我只想检索在过去 30 天内缓存的页面。

我认为有两件事不对劲...

1) GMMKTIME(0, 0, 0, 1, 1, 1, 1998)。我不确定如何将其设置为今天 - 30 天前。2)它是否会根据其标题返回我谷歌?如果 URL 没有日期超过 30 天的缓存标头,则$page变量是什么

 function exractURl()
   {
       //How to convert gmmktime to the last 30 days from today
       $ts = gmdate("D, d M Y H:i:s", gmmktime(0, 0, 0, 1, 1, 1998)) . " GMT";
       $c=  curl_init('http://www.google.co.il/');
       curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($c, CURLOPT_HTTPHEADER, array('Expires:'.$ts));
      //  What output will page give me..if the headers arent found
       $page= curl_exec($c);
       curl_close($c);
   }

更新:

   function exractURl()
   {
       $ts = gmdate("D, d M Y H:i:s", strtotime("30 days ago")) . " GMT";
       $c=  curl_init('http://www.google.co.il/');
       curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($c, CURLOPT_HTTPHEADER, array('If-Modified-Since:'.$ts));
       $page= curl_exec($c);
       curl_close($c);
       return $page;
   }
您可以使用

If-Modified-Since要求服务器仅在内容已更改时才返回内容(否则,您将收到304 Not Modified响应)。当然,这取决于服务器的行为。有关更多详细信息,请参阅此处:http://www.mnot.net/cache_docs/

要回答您关于如何获取 30 天前的时间的问题,您可以使用永远方便的strtotime

$ts = gmdate("D, d M Y H:i:s", strtotime("30 days ago")) . " GMT";