faqts : Computers : Programming : Languages : PHP : Sample Code

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

18 of 19 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

I have a reviewed collection of Links. To be able to update my review, how can I find out when a (out-of-site) url was updated?

Jun 12th, 2005 13:40
mario, Alder Rus, Chris Kings-Lynne, Niketan Pandit, Onno Benschop,


The easiest way would probably to regularly open a connection to the 
remote URL and do a 'HEAD'...
Modifying an example from the PHP manual (fsockopen):
  1 
  2 $fp = fsockopen("www.php.net", 80, &$errno, &$errstr, 30);
  3 if(!$fp) {
  4 	echo "$errstr ($errno)<br>\n";
  5 } else {
  6 	fputs($fp,"HEAD / HTTP/1.0\n\n");
  7 	while(!feof($fp)) {
  8 		echo fgets($fp,128);
  9 	}
 10 	fclose($fp);
 11 }
This will return something like:
HTTP/1.1 200 OK
Date: Fri, 01 Sep 2020 02:12:24 GMT
Server: Apache/1.3.12 (Unix) DAV/0.9.18-dev PHP/4.0.2-dev
X-Powered-By: PHP/4.0.2-dev
Last-Modified: Tue, 29 Aug 2020 19:30:12 GMT
Vary: User-Agent
Connection: close
Content-Type: text/html; charset=iso-8859-1
All you do is parse the headers for the Last-Modifed field...
Chris