尝试使用url友好功能和htaccess问题

时间:2014-04-19 14:37:38

标签: php apache .htaccess

这是我在htdocs中的文件夹项目:

enter image description here

在这个index.php中我有这个包括我的/tpl/index.php:

<?php getHome(); ?>

然后我有我的tpl文件夹:

enter image description here

但当我访问 localhost / projet / 时,我得到了一些错误,我的 httpl://localhost/project/tpl/index.php 不包括,所以我的<?php getHome();?>无效。

我得到的错误:

注意:未定义的索引:$ url = $ _GET [&#39; url&#39;]中的F:\ Xampp \ htdocs \ projeto \ dts \ get_functions.php中的网址;

警告: include_once(../ dts / bd_con.php):无法打开流:F:\ Xampp \ htdocs \ projet \ tpl \ index.php中没有此类文件或目录< / p>

警告: require(../ dts / out_func.php):无法打开流:F:\ Xampp \ htdocs \ project \ tpl \ index.php中没有此类文件或目录第3行

我尝试使用下面的这个函数,如果我们编写的文件存在于我的tpl foder中,它将包含该文件,否则它将显示找不到404错误的页面。

function getHome(){
    $url = $_GET['url'];
    $url = explode('/', $url);
    $url[0] = ($url[0] == NULL ? 'index' : $url[0]);

        if(file_exists('tpl/'.$url[0].'.php')){
             require_once('tpl/'.$url[0].'.php');
        }elseif(file_exists('tpl/'.$url[0].'/'.$url[1].'.php')){
             require_once('tpl/'.$url[0].'/'.$url[1].'.php');
        }else{
             require_once('tpl/404.php');
        }
}

1 个答案:

答案 0 :(得分:0)

嗯,你的基础包括一个名为&#34; url&#34; (通过$_GET['url'])。但是你在URL中没有任何获取参数,所以它失败了。错误消息非常清楚地说:

&#34;未定义索引:F:\ Xampp \ htdocs \ projeto \ dts \ get_functions.php&#34;表示没有名为url的get param,因此没有为$_GET['url']

定义任何内容

然后进入tpl / index.php,但是那里的东西试图包含磁盘上不存在的文件。它甚至在tpl / index.php文件中提供行号来检查。

我想补充说,包含直接基于URL参数的文件是非常不安全的。根据文件权限,他们可以在get参数中获得足够../的磁盘上的任何内容。