Location: PHPKode > scripts > HTTP Request class > http-request-class/proxyhead.php
<?php
// Credits: getHeaders and connect functions where posted at the faqts.com knowloadge base by Cinley Rodick

	// This function returns an associative array returning any 
	// of the various components of the headers
	function getHeaders($header) {
		$lines = explode("\r\n",$header);
		$headers = Array();
		
		foreach($lines as $line) {			
			$header = explode(':',$line,2);
			$name = strtolower($header[0]);
			
			if(isset($header[1])) {
				$headers[$name] = $header[1];
			} 
		}
		return $headers;
	}

	// Connects to URL using the HEAD method and returns headers
	function connect($remote_file) {

		$url = parse_url($remote_file);
		$port = 80;		
		$path = $url['path'];
		$host = $url['host'];		

		if(isset($url['port']) && !empty($url['port'])) {
			$port = $url['port'];
		}
		
		if(!isset($url['path'])) {
			$path = '/';
		}

		$fp = fsockopen($host, $port) or die("Could not 
connect to $host");
		
		fputs($fp,"HEAD $path HTTP/1.1\r\n");
		fputs($fp,"Host: $host\r\n");
		fputs($fp,"Connection: close\r\n\r\n");
		
		$header = '';

		while(!feof($fp)) {

			$header .= fgets($fp,1024);
    }
		return $header;
	}


if (isset($_GET[url])) {
  // connects to URL and parses the headers
  $response = connect($_GET[url]);
  $headers = getHeaders($response);
  //Now set the same returning headers to this page
  foreach ($headers as $hname=>$hvalue) {
     header("$hname: $hvalue");
     //echo ("$hname ->$hvalue<br>");
  }

} else {
	header("######## proxyhead_alert: Please set url. proxyhead.php?url=http://...  ########");
}
?>
Return current item: HTTP Request class