我用自己的模板系统制作了一个 PHP 框架,它可以在前端按我的意愿工作。模板系统使用?url=($page)
URL 的部分来确定用户请求的页面,然后显示名称为 的文件的内容($page)
。然后我使用 htaccess 来“美化”这个 URL。
但是,我现在正在扩展框架以识别 if $_GET['url']
contains backend
,如果是,请查看它是否有一个带有另一个字符串的斜杠。例如,如果值为$_GET['url']
,我希望它从后端文件夹backend/manage-gallery
中返回页面。manage-gallery
这是我现在拥有的代码。$_GET['url']
目前,如果值为后端,我可以静态检索页面(index.php) 。
public function addTpl() {
global $zip;
if(!isset($_GET['url']) || empty($_GET['url'])) {
$_GET['url'] = 'index';
}
$front = '_zip/_templates/_front/'. $zip['Template']['Front'];
$back = '_zip/_templates/_back/'. $zip['Template']['Back'];
if(strpos($_GET['url'], 'backend') !== false) {
if(file_exists($back . '/')) {
if(file_exists($back . '/index.php')) {
ob_start();
include($back . '/index.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
if($zip['Template']['Front'] == 'Refresh/multi-page') {
ob_start();
include($back . '/404.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
die(zipError('File Not Found', 'The file <b>' . secure($_GET['url']) . '</b> could not be found. Please re-check the URL; If you were directed here using a link, please report that link <b><a href="mailto:IntactDev@gmail.com">here<a/>.</b>'));
}
}
} else {
die(zipError('Template Not Found', 'The template <b>' . $zip['Template']['Front'] . '</b> could not be found. Please check your configuration file for a mistake.'));
}
} else {
if(file_exists($front. '/')) {
if(file_exists($front. '/' . secure($_GET['url']) . '.php')) {
ob_start();
include($front. '/' . secure($_GET['url']) . '.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
if($zip['Template']['Front'] == 'Refresh/multi-page') {
ob_start();
include($front. '/404.php');
$this->tpl .= ob_get_contents();
ob_end_clean();
} else {
die(zipError('File Not Found', 'The file <b>' . secure($_GET['url']) . '</b> could not be found. Please re-check the URL; If you were directed here using a link, please report that link <b><a href="mailto:IntactDev@gmail.com">here<a/>.</b>'));
}
}
} else {
die(zipError('Template Not Found', 'The template <b>' . $zip['Template']['Front'] . '</b> could not be found. Please check your configuration file for a mistake.'));
}
}
}
如何让我的代码检查 get 值是否包含后端,并查看它是否有一个带有字符串的斜杠?这是我的 htaccess
RewriteEngine On
RewriteRule ^(|/)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1