note 31023 added to function.filemtime

From: Date: Mon, 07 Apr 2003 09:56:11 +0000
Subject: note 31023 added to function.filemtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-46303@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. It requires the CURL-library, though! Obviously only works if the server transmits the Last-Modified header. :) $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://www.php.net/manual/en/function.filemtime.php http://master.php.net/manage/user-notes.php?action=edit+31023 http://master.php.net/manage/user-notes.php?action=delete+31023 http://master.php.net/manage/user-notes.php?action=reject+31023

« previous php.notes (#46303) next »