如何编写.htaccess以便它只提供表单访问?

时间:2013-10-07 17:23:12

标签: .htaccess web-development-server

这是我的代码:

<files contacts.html>
order allow,deny
deny from all
Allow from access.php
</files>

我不希望从网址直接访问contacts.html。我在index.html页面上有一个表单,其中包含一个带有操作access.php的表单。确认后,它会使用标题功能将其重定向到contacts.html。

1 个答案:

答案 0 :(得分:2)

您需要使用$_SESSION

access.php

session_start();

// some code here to authenticate

$_SESSION['hasAccess'] = true;

// redirect

contacts.html更改为contacts.php并在此页面顶部

session_start();

if($_SESSION['hasAccess'] !== true){

    header('Location: index.php');
    die;

}

// the rest of your code
相关问题