Re: [FAQ] How do I retrieve a page from a web site? (Was: PHP behaving like a user using a browser)



Great thing, but it misses an issue:
Suppose I have a file, let's call it incl.php, that I include in my
scripts, but I don't want to be accessible directly - when somebody
tries http://my.server/incl.php, though the file is actually there, I
want to display the webserver's 404 Error default message. I don't want
it to be hardcoded, though (like
$err404='<HTML><BODY>...</BODY></HTML>';), in other words I'd like to do
something like:

$err404=file_ge_contents('http://localhost/foobar.htm'); # foobar.htm
does not exist
$err404=str_replace('http://localhost/foobar.htm', __FILE__, $err404);
echp $err404;
die();

But - file_get_contents returns noting and an error:
Warning: file_get_contents(http://localhost/no_such_file.php): failed to
open stream: HTTP request failed! HTTP/1.1 404 Not Found in blahblah.php
on line 666.

what shuld I do to get the err404 page? Besides CURL, there must be
another way. :)

TIA
Mike
.



Relevant Pages