note 48252 added to function.get-headers

From: Date: Thu, 16 Dec 2004 17:34:52 +0000
Subject: note 48252 added to function.get-headers
Groups: php.notes 
Request: Send a blank email to php-notes+get-81869@lists.php.net to get a copy of this message
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; } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.get-headers.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48252 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48252&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48252&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48252&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48252&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48252&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48252&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48252&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81869) next »