note 36637 deleted from function.file-exists by sniper

From: Date: Sun, 23 Nov 2003 01:26:55 +0000
Subject: note 36637 deleted from function.file-exists by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60832@lists.php.net to get a copy of this message
Note Submitter: hubert+php at nospam ii dott nl ---- A modified/simplified version of the url_exists code form River~~. I wanted to be able to get username, password and port from the url and found a nice funtion in php that does all this and more. function url_header($url) { $a_url = parse_url($url); if (!$a_url[port]) $a_url[port] = 80; // echo "<br>host:$a_url[host]"; // echo "<br>port:$a_url[port]"; // echo "<br>path:$a_url[path]"; // echo "<br>user:$a_url[user]"; // echo "<br>pass:$a_url[pass]"; $fid = fsockopen($a_url[host], $a_url[port], $errno, $errstr, $timeout); if (!$fid) return "Host not responding"; fputs($fid, "HEAD $a_url[path] HTTP/1.0\r\nHost: $a_url[host]\r\n\r\n"); $head = fread($fid, 4096); fclose($fid); return $head; } function url_exists($url) { return preg_match('#^HTTP/.*\s+200\sOK\s#i', url_header($url)); } Hubert

« previous php.notes (#60832) next »