It works really nice, Michael, thanks again.

I have one more question, maybe you can answer me :
If the domain name has been redirected with hte permanent redirect, I
get the 301 Moved Permanently header response. But if the domain name
has been frame-forwarded, I have no header response. Is it normal ?
Do you know if there is some alternatives so I could check if the domain
name is used, even on a frame-forward type redirectection ?
Moreover, if the domain has been redirected, is it possible to get the
url it has been redirected to ?

Thanks again for your help


----- Original Message -----
From: "Michael Sims" <[EMAIL PROTECTED]>
To: "Frank Benady" <[EMAIL PROTECTED]>;
Sent: Thursday, January 24, 2002 2:28 AM
Subject: Re: [PHP] emulate a browser

> At 01:45 AM 1/24/2002 +0100, Frank Benady wrote:
> >Hi All
> >
> >Can I emulate the first request of a browser when it tries to connect
to a
> >distant server using a domain name and parse the answer from the
> >server to know if there is a website located there or if there is no
> >(or even some kind of forwarding) configured for this domain name ?
> >Is ther some http functions in PHP which permit to do this test ?
> You can use fsockopen() to open a socket connection to a remote host
> port 80 (HTTP).  If fsockopen() returns a valid file pointer then that
> means there is something listening on port 80 on the host (99% it will
be a
> web server).
> You could then use fputs() to send a request to the server, such as:
> "HEAD / HTTP/1.0\r\n\r\n"
> Normally browsers use GET instead of HEAD, but in your case you are
> interested in the servers response (the HTTP headers) and not the
> file/page itself.
> You could then use fgets() to read the response sent back from the
> and parse it to get the information you wanted (for example, look for
> "Location: ..." line in the headers to see if the page is trying to
> redirect the browser).
> I have a function that checks to see if a particular file is available
> HTTP from a remote host.  It takes a full URL and returns true if the
> page/file exists, and false if it doesn't.  With some work you could
> this script to achieve what you want.  I'm posting it below.  Ask if
> have any questions about it.
> Oh, BTW, I'm sure that I have (as usually) went totally overboard with
> function and someone will now probably point out that PHP has
> built in to do what I'm doing here...but I couldn't find it and I had
> writing this function anyway. :-)
> <?
> function http_file_exists ($url) {
>    if (!preg_match("/^http:\/\/([^\/]+)\/.*$/i",$url,$matches)) {
>      return "Error - incorrect format";
>    } else {
>      $host = $matches[1];
>      $fp = fsockopen ($host, 80, $errno, $errstr, 30);
>      if (!$fp) return "Error - couldn't connect to host";
>        else {
>          fputs ($fp, "HEAD $url HTTP/1.0\r\n\r\n");
>          $response = fgets ($fp,128);
>          fclose ($fp);
>          return (eregi("^.+200 OK.+$",$response) ? true : false);
>        }
>    }
> }
> ?>

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to