note 19266 deleted from function.file-exists by victor

From: Date: Mon, 03 Mar 2003 17:54:54 +0000
Subject: note 19266 deleted from function.file-exists by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-44793@lists.php.net to get a copy of this message
To check if a file on the internet exists, in some cases the fopen() won't work, because the webserver may return an error 404 page, so fopen returns true. To avoid this i wrote a function: function urlExists($url) { $url = ereg_replace("http://", "", $url); list($domain, $file) = explode("/", $url, 2); $fid=fsockopen($domain,80); fputs($fid,"GET /$file HTTP/1.0\r\nHost: $domain\r\n\r\n"); $gets = fgets($fid, 1024); fclose($fid); if (ereg("HTTP/1.1 200 OK", $gets)) return TRUE; else return FALSE; }

« previous php.notes (#44793) next »