PHP Classes

File: proxyhead.php

Recommend this page to a friend!
  Classes of Martin Fasani   HTTP Request class   proxyhead.php   Download  
File: proxyhead.php
Role: Auxiliary script
Content type: text/plain
Description: Proxy to retrieve headers. Credit inside source
Class: HTTP Request class
Generate Javascript to send HTTP AJAX requests
Author: By
Last change:
Date: 18 years ago
Size: 1,619 bytes


Class file image Download
// Credits: getHeaders and connect functions where posted at the 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();
$lines as $line) {
$header = explode(':',$line,2);
$name = strtolower($header[0]);
$header[1])) {
$headers[$name] = $header[1];

// 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'];

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

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

feof($fp)) {

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

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://... ########");