【问题标题】:php prevent direct access to an url which does not points a folder [closed]php阻止直接访问不指向文件夹的url [关闭]
【发布时间】:2013-04-02 17:42:29
【问题描述】:

我正在使用 .htaccess 和用户友好的链接。我的domain.com/contact 在提交表单后将页面重定向到domain.com/contact-verify。如果页面验证用户提交的数据,则将页面重定向到domain.com/thank-you-for-email。如果验证失败,则再次将页面重定向到domain.com/contact,并显示错误。 (Post - Redirect - Session Variables流)

如何防止直接访问domain.com/contact-verifydomain.com/thank-you-for-email

我搜索了.htaccess 的用法,但只能找到保护特定文件的保护。另外我在 google 上阅读了一些 $_SERVER["HTTP_REFERER"] 不可靠的信息?

请注意,我的.htaccess 中已经有Options All -Indexes

您能描述一下获胜者的方法吗?

【问题讨论】:

  • 在 domain.com/contact 中定义一个 SESSION 变量,如果没有设置这个变量,404你不想被访问的页面。

标签: php .htaccess protection methodology http-referer


【解决方案1】:

使用会话或 cookie 跟踪用户的进度。 然后对于您要限制访问的页面,添加代码以检查用户进度并在用户未达到所需进度点时重定向(或显示拒绝访问消息,无论您想做什么)。

if (!isset($_SESSION['progress']) || $_SESSION['progress'] != 2) {
    header('Location: /contact');
    exit;
}

【讨论】:

    猜你喜欢
    • 2014-10-12
    • 1970-01-01
    • 2016-03-04
    • 2012-12-02
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多