note 31023 deleted from function.filemtime by alindeman

From: Date: Mon, 07 Apr 2003 11:29:27 +0000
Subject: note 31023 deleted from function.filemtime by alindeman
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-46308@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.

« previous php.notes (#46308) next »