【问题标题】:Page navigation with php使用 php 进行页面导航
【发布时间】:2013-05-02 21:01:32
【问题描述】:

我正在尝试创建一个动态网站,index.php 在网站的内容区域中包含以下代码:

<?PHP

// if undefined then define
 if(!$od || $od == ""){
 $od = "news";
 }
// check if exists prep
 $link = 'incs'."/".$od.$ext;
 flush();
 $fp = fopen($link, "r");

// check if inclusion file not exists then return error
 if (!$fp) {
 echo "An error has ocurred while processing your request. The file linked as ?od=".$od." does not appear to exist.";
 }

// if exists then return parse
 else { 
 fclose($fp);
 include 'incs'."/".$od.$ext;
 }

echo '</body>'."\n";
echo '</html>'."\n";

?>

我在整个网站上也有各种链接到注册、登录等页面。 这些链接指向 ?od=register、?od=login 等页面。

网站将为我拉取默认文件,新闻,并在我网站的内容部分显示,但是当我点击注册时,地址栏中的 url 会更改为 /?od=register,但默认新闻仍然在内容部分,上面的代码有错误吗?还是我只是错过了什么?

附: $ext 在我的配置文件中定义为inc.php,它包含在索引页面的顶部。

【问题讨论】:

    标签: php redirect navigation hyperlink


    【解决方案1】:

    除了这是非常不安全的事实 - 您正在发出 GET 请求,请通过 $_GET 数组访问变量,即 $od = $_GET['od']

    【讨论】:

    • 我会通过检查 $op 是否为 inarray();示例 if(in_array($op, $pagenames)){ //执行包含 } 编辑:语法错误
    • 是的,恶意用户几乎可以通过 fopen 确定服务器上的文件,例如:example.com/?op=../index 通过这样做,我可以返回一个目录
    • 在执行包含之前,我需要如何设置 $op 和 $pagenames?这是否意味着我需要完全摆脱 fopen??
    【解决方案2】:

    我相信您需要使用 $_GET['od'] 或 $_REQUEST['od'] 来定义 $od

    $od = $_GET['od'];
    // if undefined then define
     if(!$od || $od == ""){
     $od = "news";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      相关资源
      最近更新 更多