0

假设,我正在建立网站。我希望用户只能访问 index.php 文件。我还有其他文件,例如 www.mydomain.com/aboutus.php 文件,如果用户在地址栏中键入,则可以访问它们。我希望用户只能访问 www.mydomain.com。

这些安全功能是如何构建的?

4

1 回答 1

0

如果我理解正确,您希望他们只能访问您的索引/根文档(www.mydomain.com/index.php 等)而不能输入:www.mydomain.com/aboutus。 php 使用 HTTP 引荐来源网址来确保他们来自的页面是正确的页面是相当简单的:

重要说明(编辑): $_SERVER 类型变量容易被客户端从 cURL 甚至 telnet 之类的东西伪造,并且可能是 CSRF 类型攻击的基础,因此这绝不是一个安全的实现与会话标记化之类的东西.

aboutus.php 在最顶部:

<?php
// Put the url they came from 
$ref = $_SERVER['HTTP_REFERER'];

if($ref !== 'http://mydomain.com/index.php') {
  die("Must come here from index");
 // uncomment below to redirect them automatically
 // header('location: index.php');
}
// Otherwise they came from index so show the page.
echo "Displaying about page:";
echo $content;
?>
于 2013-07-14T19:37:23.110 回答