【问题标题】:$_get and include php [closed]$_get 并包含 php [关闭]
【发布时间】:2013-01-08 04:01:27
【问题描述】:
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。但我似乎无法通过导航进行更改,我有这段代码,我知道缺少一些东西。

【问题讨论】:

  • 你的问题到底是什么?
  • 您确认$_GET['nav']中存储的内容了吗? var_dump 为我们服务。
  • $linkn的值是多少?
  • 你需要做if(!empty($_GET['nav'])) {{
  • 你为什么不用else if ($linkn == 'nav2')

标签: php get include


【解决方案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');
}

【讨论】:

  • 注意:允许的数组确保人们不能检索任何其他文件,然后是数组中的名称(url 注入)
  • 谢谢,酷,..你可以通过代码看到..
猜你喜欢
  • 1970-01-01
  • 2011-10-31
  • 2011-07-06
  • 1970-01-01
  • 2013-05-02
  • 2012-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多