12:26:36 AM
Thursday
Sep 09
Su M Tu W Th F Sa
567891011
12131415161718
19202122232425
262728293012
3456789

Play My Typing Game

View Some of My Artwork

Detecting HTTP Headers
I found this function, which seems faster and more efficient than php 5's get_header function.

<?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;
        }
}
?>


Read Previous:
Recursion Example Involving MySQL
Read Next:
Determining the dimensions of an image with PHP
Table of Contents


Give a listen to my music...
My Best Recordings
How my services and skills can help you:
  • Global (via Email/Skype/AIM(ichat)/Yahoo)
    • Web Development Consulting
    • Custom Web App Development (PHP/MySQL/jQuery/CSS) Cross-Browser & OS
    • Cellphone App Development (Android/MobileWeb)
    • Music Lessons & Education for Beginner Guitar, Piano, Bass, which transfers over to many other instruments I am comfortable playing but not yet at teaching.
    • Music - Soundtrack Composition & Voice Work
  • Local
    • Most all the above, but also:
      • Music Performance (Harp, Voice, Guitar, Piano, Bass, Latin Percussion)
      • Recording Live Music Audio
      • Video Streaming live music and other live events anywhere that can provide wifi
      • Training Video Streaming to your venue's trusted soundperson
Skills:
  • Global (via Email/Skype/AIM(ichat)/Yahoo)
    • Web Development Consulting
    • Custom Web App Development (PHP/MySQL/jQuery/CSS) Cross-Browser & OS
    • Cellphone App Development (Android/MobileWeb)
    • Music Lessons & Education for Beginner Guitar, Piano, Bass, which transfers over to many other instruments I am comfortable playing but not yet at teaching.
    • Music - Soundtrack Composition & Voice Work
  • Local, Most all the above, but also:
    • Music Performance (Harp, Voice, Guitar, Piano, Bass, Latin Percussion)
    • Being your venue's soundman
    • Video Streaming live music and other live events anywhere that can provide wifi
    • Training Video Streaming to your venue's trusted soundperson