View file wapirate/xhtml/oops.php

File size: 1.59Kb
<?php

if(!function_exists('xget_headers')) {

   /**

   * @return array

    * @param string $url

    * @param int $format

    * @desc Fetches all the headers

    * @author cpurruc fh-landshut de

    * @modified by dotpointer

    * @modified by aeontech

    */

    function xget_headers($url,$format=0) {

        $url_info=parse_url($url);

        $port = isset($url_info['port']) ? $url_info['port'] : 80;

        $fp=fsockopen($url_info['host'], $port, $errno, $errstr, 30);

        if($fp) {

            $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))) {

                    if($format == 1) {

                        $h2 = explode(':',$header);

                        // the first element is the http header type, such as HTTP/1.1 200 OK,

                        // it doesn't have a separate name, so we have to check for it.

                        if($h2[0] == $header) {

                            $headers['status'] = $header;

                        }

                        else {

                            $headers[strtolower($h2[0])] = trim($h2[1]);

                        }

                    }

                    else {

                        $headers[] = $header;

                    }

                }

            }

            return $headers;

        }

        else {

            return false;

        }

    }

}

?>