Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中包含页面的if语句出错_Php - Fatal编程技术网

在php中包含页面的if语句出错

在php中包含页面的if语句出错,php,Php,我有一组页面,我想根据url中的变量包含其中一个页面,但页面总是显示在仪表板上 link1 : index.php?pth=&page=dashboard link2 : index.php?pth=modules/institution&page=inst_classification 如果声明: if (isset($page) && !empty($page)) { $page = htmlspecialchars(

我有一组页面,我想根据url中的变量包含其中一个页面,但页面总是显示在仪表板上

link1 : index.php?pth=&page=dashboard
link2 : index.php?pth=modules/institution&page=inst_classification
如果声明:

if (isset($page) && !empty($page)) {
                    $page = htmlspecialchars($_GET["page"]);    
                    $pth = htmlspecialchars($_GET["pth"]);    
                }else{  
                    $page ='dashboard';
                    $pth = ''; 
                }
                include ('../admin/template/'.$template_fldr.'/html/'.$pth.$page.'.php'); 

谢谢

在写入之前访问
$page
。您也从不检查
pth
值是否存在。尝试:

if (empty($_GET['page']) || empty($_GET['pth'])) {
    $page ='dashboard';
    $pth = '';  
}else{  
    $page = htmlspecialchars($_GET["page"]);    
    $pth = htmlspecialchars($_GET["pth"]);    
}
include ('../admin/template/'.$template_fldr.'/html/'.$pth.$page.'.php'); 
如果
模块/institution/inst_分类。php
是您要查找的文件,则您可能还需要在include中添加一个
/


include(“../admin/template/”.$template_fldr./html/”.$pth./.$page..php”)-但您的问题并不清楚。

错误是什么?-此外,无需使用
isset()
!empty()
在同一子句中,仅使用
就足够了!EngType()/代码>错误总是在两个链接打印中出现的值:<代码> $Page < /代码>,错误在那里。此外,可能要考虑代码的顺序,检查是否存在“代码> $Page < /代码>,但是(从我们可以看到的)第一次声明“代码> $Page < /代码>是在相同的IF子句内。请打开错误报告。未定义变量:PageThank,出现此错误:解析错误:语法错误,意外“”。php“”(T_常量\u封装的\u字符串)我在
$page
'.php'
之间缺少
。我确定了我的答案
if (isset($_GET["page"]) && isset($_GET["pth"])) {
                    $page = htmlspecialchars($_GET["page"]); 
                    $pth = htmlspecialchars($_GET["pth"]);
                } else {
                    $page = 'dashboard';
                    $pth = '';
                }
                include ('../admin/template/'.$template_fldr.'/html/'.$pth.'/'.$page.'.php');