Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve http page from another host server with php and detect redirect
    text
    copied!<p>Let's say I have a server at www.myhost.com. From there by using php I want to retrieve the html document that the php file www.anotherhost.com/somefile.php produces. I also want to use php to do this. anotherhost is not on the same server as myhost.</p> <p>I know that functions such as fopen, f_get_contents and file can do this by simply executing e.g.</p> <pre><code>$fp = fopen ("http://www.anotherhost.com/somefile.php") </code></pre> <p>and from there fp can be used as any other file pointer to read the contents.</p> <p>BUT, for some reason I also want to know if somefile.php at anotherhost ordered a client-side redirect when I tried to retrieve somefile.php´s resulting html document. somefile.php can do this by</p> <pre><code>header ("Location: http://www.anotherhost.com/extrafile.php") </code></pre> <p>Now fopen will retrieve the html document that extrafile.php produces, without detecting that a client-side redirect has been performed.</p> <p>Is there some functionality in PHP that enables you to retrieve html documents from other servers AND notifies you if a redirect has taken place? It is acceptable if I must follow the redirect by myself (not done automatically), as long as I'm told what the new URL is.</p> <p>Executing arbitrary commands with the function system is not preferred.</p> <p>PS. If you are going to suggest fsockopen, then please explain why i get the error "Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?" when I try to execute</p> <pre><code>fsockopen ("http://localhost") </code></pre> <p>and I also get "Failed to parse address "localhost" when I do</p> <pre><code>fsockopen ("localhost") </code></pre> <p>Thanks for reading. Help would be greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload