note 48252 deleted from function.get-headers by nlopess
| From: | nlopess@php.net | Date: | Thu, 20 Jan 2005 13:21:30 +0000 |
| Subject: | note 48252 deleted from function.get-headers by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83681@lists.php.net to get a copy of this message | ||
Note Submitter: dotpointer
----
In response to Jamaz sollution...
I found out that sometimes when parsing an URL,
PHP is not adding some of the items to the array
you are using in the function you added here.
This results in notices from PHP when running the code.
Here is a small modification of your code, I've added
@-chars before the $url_info-calls. This prevents the
notices :)
<?
if(!function_exists('get_headers')) {
/**
* @return array
* @param string $url
* @desc Fetches all the headers
* @author cpurruc fh-landshut de
* @modified by dotpointer
*/
function get_headers($url) {
$url_info=parse_url($url);
$fp=fsockopen($url_info['host'], 80, $errno, $errstr, 30);
if($fp) {
$head = "HEAD
".@$url_info['path']."?".@$url_info['query']."
HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";
fputs( $fp, $head );
while(!feof($fp)) {
if($header=trim(fgets($fp, 1024))) {
$headers[]=$header;
}
}
return $headers;
}
}
}
?>