Page 1 of 1

Small PHP code please help: newbie

Posted: Wed Jan 09, 2008 10:07 pm
by fqservers
Dear users,

I have the following function

Code: Select all

<? 
$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 execute 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

Re: Small PHP code please help: newbie

Posted: Thu Jan 10, 2008 7:33 pm
by ianhull

Code: Select all

if(!$URL){
exit();
};//end if

Re: Small PHP code please help: newbie

Posted: Thu Jan 10, 2008 9:57 pm
by RobertGonzalez
It will also help you immensely if you don't suppress your errors (using '@').

Re: Small PHP code please help: newbie

Posted: Fri Jan 11, 2008 10:56 am
by Jonah Bron
What you really want is to use file_exists():

Code: Select all

function xxx(){
    if (!file_exists($url)){
        exit();
    }else{
        //blah blah blah
    }
}
No! What happened to

Code: Select all

?

Re: Small PHP code please help: newbie

Posted: Sat Jan 12, 2008 10:48 am
by RobertGonzalez
Remember too that there is a php.ini setting called allow_url_fopen. If it is off then you won't be able to open URLs as files.