Re: [PHP] emulate a browser
If it is frame forwarded, you would get a 300 OK status becuase you have accessed a web page and it has been server OK. The webpage (which contains the tags) then send a request to another server to get the page to be redirected to. The only way to check for this would be to see if the page you have sent the request for contains the tags (use GET instead of HEAD) but this would be unreliable as a lot of websites start with a frame based page anyway. LJ "Frank Benady" <[EMAIL PROTECTED]> wrote in message 004301c1a4ba$478a41c0$0101@phoenix">news:004301c1a4ba$478a41c0$0101@phoenix... > 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 > > Frank > > - Original Message - > From: "Michael Sims" <[EMAIL PROTECTED]> > To: "Frank Benady" <[EMAIL PROTECTED]>; > <[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 > remote > > >server to know if there is a website located there or if there is no > hosting > > >(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 > via > > 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 > only > > interested in the servers response (the HTTP headers) and not the > actual > > file/page itself. > > > > You could then use fgets() to read the response sent back from the > server > > and parse it to get the information you wanted (for example, look for > a > > "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 > via > > 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 > modify > > this script to achieve what you want. I'm posting it below. Ask if > you > > have any questions about it. > > > > Oh, BTW, I'm sure that I have (as usually) went totally overboard with > this > > function and someone will now probably point out that PHP has > something > > built in to do what I'm doing here...but I couldn't find it and I had > fun > > 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 (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] emulate a browser
At 10:33 AM 1/24/2002 +0100, Frank Benady wrote: >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 ? I'm not really sure what you mean by frame-forwarded. The only methods of redirection that I'm really familiar with are: 1. An HTTP header redirect, such as "Location: http://somewhere"; 2. A refresh meta tag in the actual body of the document, such as: http://somewhere";> 3. A javascript redirect like so: http://somewhere'"> I'm sure there are many other methods but those are the only three that I am personally familiar with. Number 1 is easy to figure out by simply parsing the HTTP header that is returned to you from the remote server. Numbers 2 and 3 are trickier, because you actually have to read the page in and parse it. I'd probably do so using a regex to try and determine if these redirect methods exist and where they are going if so. Number 3 is further complicated by the possibility of the redirect being wrapped up inside a JavaScript function so that makes it even harder to find using a regex. Maybe someone else reading this can give you some more/better information... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] emulate a browser
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 Frank - Original Message - From: "Michael Sims" <[EMAIL PROTECTED]> To: "Frank Benady" <[EMAIL PROTECTED]>; <[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 remote > >server to know if there is a website located there or if there is no hosting > >(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 via > 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 only > interested in the servers response (the HTTP headers) and not the actual > file/page itself. > > You could then use fgets() to read the response sent back from the server > and parse it to get the information you wanted (for example, look for a > "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 via > 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 modify > this script to achieve what you want. I'm posting it below. Ask if you > have any questions about it. > > Oh, BTW, I'm sure that I have (as usually) went totally overboard with this > function and someone will now probably point out that PHP has something > built in to do what I'm doing here...but I couldn't find it and I had fun > 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 (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] emulate a browser
Thanks for your help Michael, I'll try it out. Frank > 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 remote > >server to know if there is a website located there or if there is no hosting > >(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 via > 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 only > interested in the servers response (the HTTP headers) and not the actual > file/page itself. > > You could then use fgets() to read the response sent back from the server > and parse it to get the information you wanted (for example, look for a > "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 via > 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 modify > this script to achieve what you want. I'm posting it below. Ask if you > have any questions about it. > > Oh, BTW, I'm sure that I have (as usually) went totally overboard with this > function and someone will now probably point out that PHP has something > built in to do what I'm doing here...but I couldn't find it and I had fun > 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 (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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 remote >server to know if there is a website located there or if there is no hosting >(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 via 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 only interested in the servers response (the HTTP headers) and not the actual file/page itself. You could then use fgets() to read the response sent back from the server and parse it to get the information you wanted (for example, look for a "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 via 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 modify this script to achieve what you want. I'm posting it below. Ask if you have any questions about it. Oh, BTW, I'm sure that I have (as usually) went totally overboard with this function and someone will now probably point out that PHP has something built in to do what I'm doing here...but I couldn't find it and I had fun writing this function anyway. :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] emulate a browser
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 remote server to know if there is a website located there or if there is no hosting (or even some kind of forwarding) configured for this domain name ? Is ther some http functions in PHP which permit to do this test ? Thanks in advance Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]