包含使用$ _GET在URL中选择的页面

时间:2017-12-29 14:40:14

标签: php url

我想创建一个页面,其中包含自己所选择的页面选择URL(示例:index.php?p=signin并提供保护。我可以保护更多页面吗?

我不会保护$_GET['p']的文字免于注射。我只是想知道这种方法是否危险?

$grantLevel = [
    'Banned'                => 0 ,
    'Guest'                 => 1 ,
    'Trial'                 => 2 ,
    'Normal'                => 4 ,
    'Premium'               => 8 ,
    'Moderator'             => 16 ,
    'Administrator'         => 32 ,
    'SuperAdministrator'    => 64 
] ;

$pages = [
    'ban'       => $grantLevel['Banned'] ,
    'error'     => $grantLevel['Guest'] ,
    'forbidden' => $grantLevel['Guest'] ,
    'manage'    => $grantLevel['Administrator'] ,
    'signin'    => $grantLevel['Guest'] ,
    'welcome'   => $grantLevel['Guest'] ,
];


$accountLevel = $_SESSION['accountLevel'] ;


if($accountLevel != $grantLevel['Banned']){   

    if(isset($_GET['p'])) {

        if($accountLevel >= $pages[ $_GET['p']]) { 

            $p = $_GET['p'] ;

        } else {

            $p = 'forbidden' ;
        }
    } else { 

        $p = 'error' ;
    }    
} else {

    $p = 'ban' ;
}

require( $p . '.php') ;

0 个答案:

没有答案