fqservers Posted January 10, 2008 Share Posted January 10, 2008 Dear users, I have the following function <? $page = 0; $URL = "http://www.xxxxxxx.com/yyyyy.php/"; $page = @fopen($URL, "r"); And the function continues. I would like to exit the function if the above http://www.xxxxxxx.com/yyyyy.php/ does not exit. Because right now when i execite it for a non existing .php file it crashes my computer. I would really appreciate any help. Thank you. P.S I have very little knowledge of PHP Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 Try <?php $page = 0; $URL = "http://www.xxxxxxx.com/yyyyy.php/"; if (!fopen($URL, "r")) exit(); $page = @fopen($URL, "r"); ?> Quote Link to comment Share on other sites More sharing options...
fqservers Posted January 11, 2008 Author Share Posted January 11, 2008 Try <?php $page = 0; $URL = "http://www.xxxxxxx.com/yyyyy.php/"; if (!fopen($URL, "r")) exit(); $page = @fopen($URL, "r"); ?> OMG it worked. Thank you so much: now rather than crashing my computer it displays the follwoing message. Warning: fopen(http://www.xxxxxxx.com/yyyyy.php/) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/jessy/public_html/yyyyy.php on line 74 is it possible to alter this error message? thank you for your help again. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 11, 2008 Share Posted January 11, 2008 Define alter this message. Does xxxxxxx.com and yyyyy.php exist? Quote Link to comment Share on other sites More sharing options...
fqservers Posted January 11, 2008 Author Share Posted January 11, 2008 Define alter this message. Does xxxxxxx.com and yyyyy.php exist? yes they do exit and some times it is possible that they are not online. How can I define alter this message? I have very little experience in PHP I would reall apreciate if you can provide me more detail. thank you Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 <?php $URL = "http://www.xxxxxxx.com/yyyyy.php/"; if (!$page = @fopen($URL, "r")) { exit(); } ?> Quote Link to comment Share on other sites More sharing options...
abdfahim Posted January 11, 2008 Share Posted January 11, 2008 there is know need for using extra $page = @fopen($URL, "r"); , because when you write if (!fopen($URL, "r")) exit(); , it means the program will exit if it can't open file or it'll open the file if it can. Quote Link to comment Share on other sites More sharing options...
fqservers Posted January 12, 2008 Author Share Posted January 12, 2008 Thank you all for your help. You solve my major problem but I still get an error message " Warning: fopen(http://www.xxxxxxx.com/yyyyy.php/) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/jessy/public_html/yyyyy.php on line 74" I would like to have a custom error message. But this is minor thankx again Quote Link to comment Share on other sites More sharing options...
asmith Posted January 12, 2008 Share Posted January 12, 2008 did you use the thorpe code ? that should work fine , however if you still have it, post your final code . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.