在php中包含页面的if语句出错
我有一组页面,我想根据url中的变量包含其中一个页面,但页面总是显示在仪表板上在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(
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');