如果你正确的创建了页面,那么任何其他人没有理由访问 index.php 或 home.php 之外
的 index.php 页面。一旦 index.php 被访问后,你可以通过获得变量的方式来打开需要的页
面。你的 index 页面应该包含类似的以下代码:
2
define('yourPage',1);
然后,其它页面应该包含:
3
if (!defined('yourPage')) die('Access Denied');
这么做的目的是防止直接访问你的其它 php 页面。这样,任何试图不通过 index.php 访
“
”
问其它网页的人,将得到 访问被拒绝 的消息。
7、创建一个数据库类
如果你正在进行数据库编程(在 PHP 中非常常见的任务),一个不错的想法是创建
一个数据库类来处理任何数据库管理功能。示例代码如下:
4
public function dbExec($query)
5
6
{
7
8
$result = $this->db->exec($query);
9
10
if (PEAR::isError($result))
11
12
errorRedirect($result->getMessage(), true);
13
14
else
15
16
return $result;
17
18
}
这个函数仅接收一个查询语句并对其执行。它还处理可能出现的任何错误。你还可以
在这儿包含审核代码,不过我更喜欢使用一个类似的审核函数:
19 // checks if arguments given are integer values not less than 0 - has multiple arguments
20
21
function sanitizeInput()
22
23
{
24
25
$numargs = func_num_args();
26
27
$arg_list = func_get_args();
28
29
for ($i = 0; $i < $numargs; $i++) {