Jump to content

protecting includes?


aebstract

Recommended Posts

When you are including files, make sure you the file you are including actually exists on your server, and use your servers document root when including files, espcially when doing somthing like this:
[code=php:0]$page = $_GET['page']

include $_GET['page']. '.php';[/code]


So rather than doing the above do this:
[code=php:0]$page = $_GET['page'];
// check that the files exists first
if(file_exists('http://www.site.com/' . $page . '.php'))
{
  // if it does include it
  include $_SERVER['DOCUMENT_ROOT'] . $page . '.php';
}
// file doesnt exists, hakcing attempt!
else
{
    die('<h1>hacking attempt</h1>');
}[/code]


That isnt the best way of doing it, but is just a quick example.
Link to comment
https://forums.phpfreaks.com/topic/15263-protecting-includes/#findComment-61666
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.