-1
我正在嘗試設置一個系統以最大限度地降低人們更新網站的複雜性,因爲我不會主要更新每日內容並提供乾淨的URL。沒有數據庫的小型網站的網站結構
由於我無法使用數據庫,所有內容都駐留在兩個基本文件夾(/ private/content OR/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';
}
}
你可以添加包含內容文件的代碼嗎?我目前沒有看到阻止某人訪問「http://example.com/hello /../../../ etc/passwd」的任何內容。 – AndrewR