$ _get并包含php

时间:2013-01-08 04:01:28

标签: php get include

if (isset($_GET["nav"])) {
    if (!empty($_GET)) {
        $linkn = $_GET['nav'];
        if ($linkn == "nav1") {
            include("nav1.php");
        }
        if ($linkn == "nav2") {
            include("nav2.php");
        }
    } 
    else {
        include("nav1.php");
    }
}

我似乎无法理解nav2.php的任何想法?
对不起,我在构建它时匆匆忙忙。这里发生了什么,这是在我的index.php右侧导航,我已经为我的导航分离了php,nav1,nav2 ,.但我似乎无法改变我的导航,我有这个代码,我知道有些东西缺失。

1 个答案:

答案 0 :(得分:1)

$include = $_GET;
//Allowed navigations
$allowed = array('nav1', 'nav2');

//var must exist, have value and exist in allowed array
if (isset($_GET["nav"]) && !empty($_GET) && in_array($include, $allowed)){ 
  include($include.'.php');      
} else {
  include('nav1.php');
}