Jump to content

Small code, newbie to PHP


fqservers

Recommended Posts

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

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.