note 64073 added to function.get-headers
| From: | rsyring+phppost at gmail dot com | Date: | Thu, 06 Apr 2006 22:08:11 +0000 |
| Subject: | note 64073 added to function.get-headers | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107472@lists.php.net to get a copy of this message | ||
Once again another update. The improvements are:
HTTPS support (make sure you have SSL support enabled -- PHP5 is as simple as uncommenting
extension=php_openssl.dll in php.ini)
Fixed bug with exploding the header on ':'. This caused the location header to be broken
and just return 'http'.
Set stream timeout in addition to socket timeout.
<?php
function my_get_headers($url ) {
$url_info=parse_url($url);
if (isset($url_info['scheme']) && $url_info['scheme'] ==
'https') {
$port = 443;
@$fp=fsockopen('ssl://'.$url_info['host'], $port, $errno, $errstr,
10);
} else {
$port = isset($url_info['port']) ? $url_info['port'] : 80;
@$fp=fsockopen($url_info['host'], $port, $errno, $errstr, 10);
}
if($fp) {
stream_set_timeout($fp, 10);
$head = "HEAD
".@$url_info['path']."?".@$url_info['query'];
$head .= " HTTP/1.0\r\nHost:
".@$url_info['host']."\r\n\r\n";
fputs($fp, $head);
while(!feof($fp)) {
if($header=trim(fgets($fp, 1024))) {
$sc_pos = strpos( $header, ':' );
if( $sc_pos === false ) {
$headers['status'] = $header;
} else {
$label = substr( $header, 0, $sc_pos );
$value = substr( $header, $sc_pos+1 );
$headers[strtolower($label)] = trim($value);
}
}
}
return $headers;
}
else {
return false;
}
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 12.202.70.81
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.get-headers.php
Edit -- http://master.php.net/note/edit/64073
Del: integrated -- http://master.php.net/note/delete/64073/integrated
Del: useless -- http://master.php.net/note/delete/64073/useless
Del: bad code -- http://master.php.net/note/delete/64073/bad+code
Del: spam -- http://master.php.net/note/delete/64073/spam
Del: non-english -- http://master.php.net/note/delete/64073/non-english
Del: in docs -- http://master.php.net/note/delete/64073/in+docs
Del: other reasons-- http://master.php.net/note/delete/64073
Reject -- http://master.php.net/note/reject/64073
Search -- http://master.php.net/manage/user-notes.php