下面的代码是这样工作的:
http://www.website.com/?page=home
将从中提取内容http://www.website.com/home.php
- 或者 -
http://www.website.com/?page=About
将从中提取内容http://www.website.com/About.php
代码:
// Set the default name
$action = 'home';
// Specify some disallowed paths
$disallowed_paths = array('admin');
if (!empty($_GET['page'])) {
$tmp_action = basename($_GET['page']);
// If it's not a disallowed path, and if the file exists, update $action
if (!in_array($tmp_action, $disallowed_paths) && file_exists("{$tmp_action}.php"))
$action = $tmp_action;
}
// Include $action
include("$action.php");
?>
上面的代码适用于我的所有页面,但现在我有一个自定义链接,我需要添加它http://www.website.com/?page=Search
来从中提取内容,http://www.website.com/search/search.php
而不是http://www.website.com/Search.php
我怎样才能做到这一点?
谢谢