如何使用PHP处理403错误 [英] how to handle a 403 error with PHP

查看:488
本文介绍了如何使用PHP处理403错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个php脚本,由于$ _POST方法发送的数据的长度和内容,有时可以使服务器返回403错误消息(禁止访问).由于某些mod_secure规则会过滤服务器上发送的数据,因此返回此403错误消息.

I have built a php script that can sometimes have the server returns a 403 error message (forbidden access) because of the length and content of the data sent through the $_POST method. This 403 error message is returned because of some mod_secure rules that filtrate the data sent on the server.

是否可以让PHP处理此403错误消息? 例如,我将在运行脚本时捕获服务器状态,然后在服务器返回403状态代码时显示错误消息. 甚至可以在PHP中做到这一点吗?

Is it possible to have PHP handle this 403 error message? For example, I would to catch the server status when I run my script and then display an error message when the server returns the 403 status code. Is that even possible to do this in PHP?

换句话说,如果服务器在执行PHP脚本本身时返回403状态代码,那么我不希望进行重定向,而是在当前页面中显示自定义消息.

In other words, without making a redirection, I would just like to display in the current page a custom message if the server returns a 403 status code when the PHP script itself is executed.

感谢您的帮助

推荐答案

这将为Apache中的403错误设置一个自定义错误文档,并将其指向脚本以处理该错误.有关如何执行此操作的信息,请参考 ErrorDocument 文档.遵循以下原则:

It would be to set up a custom error document for 403 errors in Apache, and point this at a script to handle the error. Refer to the ErrorDocument documentation on how to do this, but it would be something along these lines:

ErrorDocument 403 /custom_403_handler.php

这篇关于如何使用PHP处理403错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆