note 31024 modified in ref.curl by danbrown

From: Date: Sun, 17 May 2009 19:46:25 +0000
Subject: note 31024 modified in ref.curl by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155265@lists.php.net to get a copy of this message
Here's a little code snippet if you need the last-modified-time for a remote file as filemtime() does not work on those. :) <?php $modified = ""; function read_header($ch, $header) { global $modified; $length = strlen($header); if(strstr($header, "Last-Modified:")) { $modified = substr($header, 15); } return $length; } function last_mod($remote_file) { global $modified; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $remote_file); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); $headers = curl_exec ($ch); curl_close ($ch); return $modified; } ?> use something like <?php echo strtotime(last_mod("http://www.php.net/")); ?> to get the time as an Unix timestamp or <?php echo last_mod("http://www.php.net/"); ?> to get the gmdate()-like time. --was-- Here's a little code snippet if you need the last-modified-time for a remote file as filemtime() does not work on those. :) $modified = ""; function read_header($ch, $header) { global $modified; $length = strlen($header); if(strstr($header, "Last-Modified:")) { $modified = substr($header, 15); } return $length; } function last_mod($remote_file) { global $modified; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $remote_file); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); $headers = curl_exec ($ch); curl_close ($ch); return $modified; } use something like echo strtotime(last_mod("http://www.php.net/")); to get the time as an Unix timestamp or echo last_mod("http://www.php.net/"); to get the gmdate()-like time. http://php.net/manual/en/ref.curl.php

« previous php.notes (#155265) next »