Jump to content

Recommended Posts

Looks alright to me. I would go as far to say that I would setup an array "white" list instead though:

 

$page = isset($_GET['act'])?strtolower($_GET['act']):'index'; // default to index if no data
$validPages = array("index", "view", "user", "contact"); // example white list

if (in_array($page, $validPages)) {
    include('./pages/'.$page.'.php');
}

 

But your way is secure, given that you verify the file_exists. Just another way of doing it :)

Link to comment
https://forums.phpfreaks.com/topic/190453-including-pages/#findComment-1004629
Share on other sites

I would recommend validating exactly what is in the $_GET variable using the method that premiso just posted.

 

Consider this sequence of events - you are including content into a general purpose index.php page using this method and you also have an admin section on your site with its own index.php page that is setup with its' own include files for the admin functions on your site. Someone can use directory transversal by suppling the correct ../../../path_to_your_admin_include_page/ and cause any of the the admin include files to be included on the current page. The file_exists() logic WILL be TRUE but they have just accessed your admin functions and can do anything an admin has permission to do.

Link to comment
https://forums.phpfreaks.com/topic/190453-including-pages/#findComment-1004635
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.