Dynamic Include Safety

前端 未结 4 1431
一向
一向 2021-01-14 14:05

Is there any way to safely include pages without putting them all in an array?

if (preg_match(\'/^[a-z0-9]+/\', $_GET[\'page\'])) {

$page = $_GET[\'page\'].\".ph         


        
4条回答
  •  执念已碎
    2021-01-14 14:49

    Despite what you stated about not wanting to store a list of available pages in an array it is likely going to be the best, non-db, solution.

    $availFiles = array('index.php', 'forum.php');
    if(in_array($_GET['page'].".php", $availFiles))
     {
       //Good
     }
    else
     {
       //Not Good
     }
    

    You could easily build the array dynamicly with either DB queries or by reading a file, or even reading the contents of a directory and filtering out the things you don't want available.

提交回复
热议问题