发送 HTTP 403.6 状态代码

发布于 2024-11-02 03:12:06 字数 372 浏览 0 评论 0原文

在我们的某些系统中,我们有一个 IP 地址黑名单,可以阻止某些 IP 查看网站。目前,PHP 只是发出文本,说明您的 IP 地址已被阻止等等。

但是

我遇到了 HTTP 错误代码 403,更准确地说是错误代码 403.6 (http://en.wikipedia.org/wiki/HTTP_403)我认为这比仅仅文本更好。

但我在某处读到 .6 仅适用于 Windows 或类似的东西?

我可以通过 PHP 从 LAMP 服务器发送 403.6 标头吗?这是否比仅发送“您已被阻止的文本”更好?

In some of our systems we have a blocklist of IP address which stops certain IP's viewing the website. Currently the PHP just issues text saying your ip address has been blocked blah blah blah.

HOWEVER

I have come across the HTTP Error Code 403 and to be more exact error code 403.6 (http://en.wikipedia.org/wiki/HTTP_403) which I think would be better than just text.

But i read somewhere that the .6 is only for windows or something along those lines??

Can I send a 403.6 header through PHP from my LAMP servers and would this be better practice than just sending "you've been blocked text"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

花海 2024-11-09 03:12:06

发送一个简单的 403,因为它是禁止的正确代码,然后发送自定义短信,以便您的用户了解发生了什么。

示例 php 代码如下。

<?php
header("HTTP/1.0 403 Forbidden");
?>

<h1>Access Forbidden!</h1>

You have been banned from seeing our site because xx and you will
xx etc ... 

Send a simple 403 as it's the correct code for forbidden and then send a custom textual message so your users understand what's going on.

Sample php code bellow.

<?php
header("HTTP/1.0 403 Forbidden");
?>

<h1>Access Forbidden!</h1>

You have been banned from seeing our site because xx and you will
xx etc ... 
夜空下最亮的亮点 2024-11-09 03:12:06

如果某些 IP 地址因被列入黑名单而被阻止,则可以返回简单的 404“未找到”HTTP 状态,特别是对于已标记为“恶意”的地址。

不要向他们提供任何他们可以使用的信息。只需说“这里没什么可看的”,而不是“这里有一些你不被允许看到的东西”。

无论如何,始终尝试提供需要了解的信息。

If certain IP addresses have been blocked because they are blacklisted, then it is allright to return a simple 404 "Not Found" HTTP status, especially for addresses that have been marked as 'malicious'.

Don't give them any information they can use. Just say 'nothing to see here' instead of 'here is something you are not allowed to see'.

In any case, always try to provide information on a need-to-know basis.

多情癖 2024-11-09 03:12:06

根据 HTTP 的定义方式,在真正的标准方式中,您的服务器应使用自定义的 4xx HTTP 状态代码进行响应。 4xx 范围内的许多未使用的状态代码可供您使用。

可以在此处找到已在使用的状态代码列表。

编辑:

您应该同时使用状态代码和消息,但与已定义的状态代码和消息无关。作为示例,您可以使用:

455 Your access has been blocked for excessive crawling

According to the way HTTP was defined, in true standard way your server should respond with a custom 4xx HTTP status code. Many unused status codes in the 4xx range are available for your use.

And a list of already in use status codes can be found here.

Edit:

You should use both status code and message, but one unrelated to the ones already defined. As an example you could use:

455 Your access has been blocked for excessive crawling
浴红衣 2024-11-09 03:12:06

您可以在 Apache 服务器上设置一个 .htaccess 文件来阻止 IP 地址,其中可以在规则中包含所有被阻止的 IP 范围。 403 消息的错误消息(针对阻止的连接显示)也可以自定义与 .htaccess 文件

You could have a .htaccess file setup on your Apache server to block the IP addresses which can include all your blocked IP ranges in a rule. The error message for the 403 message (which is displayed for blocked connections) can also be customized with the .htaccess file.

回首观望 2024-11-09 03:12:06

如果您要像这样当着用户的面关上门,我认为通过简单的 403 返回 403.6 没有任何意义。

如果出于用户友好性的考虑,您希望通知用户发生了什么事(可能会为用户提供一些联系信息),则最好选择发送 200 并附带适当的消息。相信他们被错误地阻止等等)。

在“关上门”方法(技术上更正确)和“友好”方法(对您的人类用户更好)之间进行选择是您的决定。

I don't think there is any point in returning a 403.6 over a plain 403 if you are going to slam the door in the user's face like that.

The other option, sending a 200 instead with an appropriate message is preferable if, in the interest of user-friendliness, you want to notify the user of what has happened (possibly provide some contact information for those who believe they are being blocked erroneously etc).

Choosing between the "slam the door" approach (which is technically more correct) and the "friendly" approach (which is better for your human users) is your call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文