note 42983 deleted from function.get-headers by nlopess

From: Date: Mon, 06 Sep 2004 17:00:12 +0000
Subject: note 42983 deleted from function.get-headers by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76108@lists.php.net to get a copy of this message
Note Submitter: ---- In a question about receiving headers with gZip encoding. I have rewritten the previous function. Remember it's the request that you make, that changes the response. <?php /** * @return array * @param string $url * @desc Fetches all the headers sent by the server in response to a HTTP request. * @author skinums <skinums_frostbot_com> */ function get_headers_php4($url,$gzip = false) { $url_info = parse_url($url); $fp = fsockopen($url_info['host'],80,$errno,$errstr,30); if (!$fp) { exit; } else { $head = "GET ".$url_info['path']."?".$url_info['query']." HTTP/1.0\r\n"; $head .= "Host: ".$url_info['host']."\r\n"; $head .= "Connection: close\r\n"; if ($gzip) { $head .= "Accept-Encoding: gzip\r\n"; } $head .= "\r\n"; fputs($fp,$head); while(!feof($fp)) { $line = fgets($fp,1024); if (strpos($line,"\r\n",0) === 0) { fclose($fp); return $header; } else { $header[] = $line; } } } } ?> -= skin =-

« previous php.notes (#76108) next »