Small PHP code please help: newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fqservers
Forum Newbie
Posts: 1
Joined: Wed Jan 09, 2008 10:02 pm

Small PHP code please help: newbie

Post 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
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Re: Small PHP code please help: newbie

Post by ianhull »

Code: Select all

if(!$URL){
exit();
};//end if
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Small PHP code please help: newbie

Post by RobertGonzalez »

It will also help you immensely if you don't suppress your errors (using '@').
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Small PHP code please help: newbie

Post 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

?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Small PHP code please help: newbie

Post 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.
Post Reply