我正在尝试设置一个系统,以尽量减少更新网站的人员的复杂性,因为我不会是更新日常内容的主要人员,也不会提供干净的 URL。
由于我无法使用数据库,所有内容都位于两个基本文件夹之一(/private/content 或 /private/utilities)。对于正常的每日更新,不需要访问实用程序(包含页面包装器 - 页眉、导航、页脚等)文件夹。这最大限度地减少了日常编辑器的可见代码量。
我创建了一个数组 ($allowedContent),其中包含可访问的有效部分的列表。代码针对该数组进行测试,以验证用户没有尝试访问不适当的内容。使用下面的代码,这些请求将成功。其他一切都会失败。
- www.example.com/
- www.example.com/popup/*
- www.example.com/test
- www.example.com/hello
- www.example.com/foobar
我的问题是:这种方法有什么突出的问题吗?
.htaccess
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
PHP
// parse the URL
$requestURI = explode('/', $_SERVER['REQUEST_URI']);
//print_r ($requestURI);
// a list of non-restricted dynamic content
$allowedContent = array("test", "hello", "foobar");
$allowAccess = false; // assume hackers :o
// determine the section
if (!$requestURI[1]) { // none defined - use root/home
$section = 'home';
$skin = true;
$allowAccess = true;
} elseif ($requestURI[1] == 'popup') { // popup - no skin
$section = $requestURI[2];
$skin = false;
$allowAccess = true;
} else {
if (in_array($requestURI[1], $allowedContent)) { // verify that the requested content is allowed / prevent someone from trying to hack the site
$section = $requestURI[1];
$skin = true;
$allowAccess = true;
} else { // this would be either a 404 or a user trying to access a restricted directory
echo "evil laugh"; // obviously, this would change to a 404 redirect
}
}
添加了调用内容的代码
// call the relevant content pieces
if ($allowAccess == true) {
if ($skin == true ) {
// call wrapper part 1
include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/wrapperOpen.php';
// call aside
include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/header.php';
// call aside
include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/aside.php';
}
// call CONTENT (based on section)
include $_SERVER['DOCUMENT_ROOT'] . '/private/content/' . $section . '/index.php';
if ($skin == true ) {
// call branding
include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/branding.php';
// call footer
include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/footer.php';
// call wrapper part 2
include $_SERVER['DOCUMENT_ROOT'] . '/private/utilities/wrapperClose.php';
}
}