使用$ _GET时,File_exists变量返回false

时间:2015-07-19 22:18:52

标签: php

好吧,所以,我想创建一个脚本,它使用url变量来显示页面,并在加载之前检查它们以防止php错误,但file_exists变量每次都返回false,继承代码:

<?php
if (!empty($_GET["page"])) {

    if (file_exists("any/" . $GET["page"] . ".php")) {

        include("any/" . $_GET["page"] . ".php");

    } else { echo "404"; }


} else {

    include("any/index.php");
} 
?>

index.php以及“any”文件夹中的

index.phpfile-1.php内容是他们的名字。

我访问过:index.php?page=index从file_exists变量返回404,当我访问index.php?page=file-1时返回了该内容,当我刚刚访问index.php时未显示“404”消息或index.php?page=如果删除该检查程序,则该问题不存在,但是,它在不存在的文件中显示包含变量错误。

1 个答案:

答案 0 :(得分:1)

我看到你正在使用$ GET [&#34; page&#34;]而不是$ _GET [&#34; page&#34;]所以我建议你解决这个问题然后再试一次。