【问题标题】:Restrict access with htaccess but allow from web pages使用 htaccess 限制访问,但允许从网页访问
【发布时间】:2012-07-26 18:52:16
【问题描述】:

如何限制使用 .htaccess 文件 Deny from all 的访问,但所有 $.post 请求、$.get 请求等。我怎样才能仍然从页面访问文件,但只需进入该文件即可撤销直接访问浏览器?

【问题讨论】:

  • 所以你只想允许 POST 请求而不是 GET?
  • if (empty($_POST) || empty($_SERVER['HTTP_REFERER'])) { header("{$_SERVER['SERVER_PROTOCOL']} 403 Forbidden"); exit; }?
  • 只允许对页面的 AJAX 请求?并禁止从浏览器访问?
  • @MikeBrant 不允许两者,但阻止用户在浏览器中访问文件 (php)。 (例如website.com/restricted/file.php)。我会澄清的。
  • $.post$.get ,jQuery AJAX 吗?

标签: php javascript .htaccess post restriction


【解决方案1】:

您可以通过 mod_rewrite 和类似条件使用 HTACCESS 禁用浏览器访问

RewriteCond %{HTTP_USER_AGENT} ^.*Firefox/4.*$
RewriteRule . - [R=404,L,NS]

ErrorDocument 404 /error.php?e=404

要访问该页面,您可以使用带有类似选项的 cURL

curl_setopt($ch, CURLOPT_USERAGENT, "allowed_agent");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-15
    • 2011-07-03
    • 2011-01-02
    • 2014-08-11
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 2012-11-05
    相关资源
    最近更新 更多