note 36637 added to function.file-exists

From: Date: Thu, 16 Oct 2003 20:59:50 +0000
Subject: note 36637 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-58720@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36637 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36637&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36637&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58720) next »