Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

http status code 403 - how to handle a 403 error with PHP

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.

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?

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.

thanks for your help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...