SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: header info...

  1. #1
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    header info...

    Any one know how to use PHP to display the Header Information from a host using a domain name? Similiar to Netcraft...
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  2. #2
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All the server information is contained in the HTTP_SERVER_VARS and the like aren't they, like the OS is in OS in the environmentals, and like the server vars holds the server software, ie apache with php.

    Looking at my phpself page, all the information is contained in there, under each of the sections.

    Whoops, this time after reading your post, no I'm not quite sure.
    Oh no! the coots are eating my nodes!

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this what you are after?

    PHP Code:
    <?

        
    function freddysheader($url) {
            
    $fp fsockopen ($url80$errno$errstr30);
            if (!
    $fp) {
                print 
    "Error String: $errstr; Error No. ($errno)<br>\n";
                } 
            else {
                
    fputs ($fp"GET / HEAD HTTP/1.1\r\n\r\n");
                while (!
    feof($fp)) {
                    
    $data .= fgets ($fp,128);
                    }
                
    fclose ($fp);
                }
            
    ereg("Server:(.*)Connection:"$data$args);
            return 
    $args[1];
            }

    print 
    freddysheader("www.domain.com");
    ?>
    Last edited by freddydoesphp; Aug 21, 2001 at 23:02.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And for a more in-depth description go to http://php.net/freddysheader
    ck :: bringing chris to the masses.

  5. #5
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wonder how many people have clicked on that

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  6. #6
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't work I keep getting error number 0... I'm still working on it though!!! Thanks for the starting code, hopefully I'll be able to figure it out.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe its your version of PHP, I think ealier version have sockets disabled on windows platforms, at least I think. Anyways, what url did you try? I could put this code up on a server for you so you can see it working.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW I changed the ereg part around and this seems to work better.

    PHP Code:
    <?
        
    function freddysheader($url) {
            
    $fp fsockopen ($url80$errno$errstr30);
            if (!
    $fp) {
                print 
    "Error String: $errstr; Error No. ($errno)<br>\n";
                } 
            else {
                
    fputs ($fp"GET / HEAD HTTP/1.1\r\n\r\n");
                while (!
    feof($fp)) {
                    
    $data .= fgets ($fp,128);
                    }
                
    fclose ($fp);
                }
            
    ereg("^([^<]*)"$data$args);
            return 
    $args[1];
            }

    print 
    freddysheader("www.yahoo.com");
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When including http:// you get:

    Error String: ; Error No. (0)

    You don't need to include it

    Tried the second version of the code and get:

    HTTP/1.1 400 Bad Request Date: Wed, 22 Aug 2001 18:58:45 GMT Content-Length: 219 Content-Type: text/html Server: NetCache (NetApp/5.1R2D1)

    This is using Windows Me

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  10. #10
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! Thank you for the help! I think I got it.. at least kinda, will post finished code and URL after I get it perfected.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  11. #11
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Version .000009

    PHP Code:
    <?



        
    function freddysheader($url) {
            
    $url str_replace("http://"""$url);
            
    $fp fsockopen ($url80$errno$errstr30);
            if (!
    $fp) {
                print 
    "Error String: $errstr; Error No. ($errno)<br>\n";
                } 
            else {
                
    fputs ($fp"GET / HEAD HTTP/1.1\r\n\r\n");
                while (!
    feof($fp)) {
                    
    $data .= fgets ($fp,128);
                    }
                
    fclose ($fp);
                }
            
    ereg("^([^<]*)"$data$args);
            return 
    $args[1];
            }

    print 
    freddysheader("http://www.php.net");
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  12. #12
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had written a similiar script, but it took FOREVER to run. It would run, just not real fast, and it didn't like IIS servers. Well, thank you Freddy! I learned a lot form this litle adventure! Finished code below:

    PHP Code:
    <?
        
    function check_header($url) {
        if(
    eregi("http://",$url)){
            
    $url eregi_replace("http://","",$url);
        }
            
    $fp fsockopen ($url80$errno$errstr30);
            if (!
    $fp) {
                print 
    "Invalid Domain<p>";
                } 
            else {
                
    fputs ($fp"GET / HEAD HTTP/1.1\r\n\r\n");
                while (!
    feof($fp)){
                    
    $data .= fgets ($fp,128);
                }
                
    fclose ($fp);
                }
            
    ereg("^([^<]*)"$data$args);
            return 
    $args[1];
            }

    if(
    $domain){
    $data =  check_header("$domain");
    print 
    "<fonnt face=Verdana,Arial><b>Server Information For $domain</b></font><p>";
    $data explode("\n"$data);
    foreach(
    $data AS $line){
        if(
    eregi("server:"$line)){
            print 
    eregi_replace("server: ","",$line) ."<p>";
            
    $i++;
        }
    }
    if(!
    $i){
        echo(
    "No Server Information Provided<p>");
    }
    }
    ?>
          <font face="Verdana,Arial,Helvetica, sans-serif" size="2">
          <b>Show the server response headers for a requested URL:</b>
          <form method="GET" action=" <?=$PHP_SELF?>">
            <div align="center"><table border="0"  height="112" align="center">
              <tr>
                <td align="right"><font face="Arial,Helvetica, sans-serif" size="-1">URL:</font></td>
                <td><input type="text" name="domain" size="40"></td>
              </tr>
              <tr>
                <td></td>
                <td><input type="submit" value="Get Headers"></td>
              </tr>
            </table>
            </center></div>
          </form>
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  13. #13
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replacing the http:// was my idea first
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •