简体   繁体   中英

php logging of 403 errors

In htaccess I've set up ErrorDocument 403 to some friendly php page, as in:

ErrorDocument 403 http://www.site.com/error/403-forbidden.php

The thing is, I'd like to find an easy way to keep track of all the 403-forbidden's that happen on the site. So far I have the PHP code to send me an email with their IP, etc., but what I cannot find is something that will also tell me how the person ended up there.

So for example in htaccess I have a rule that forbids the use of the dollar sign ($) in URL's. So, if I deliberately go: http://www.site.com/ $ I get redirected to the 403-forbidden.php script. In this script, is there a way to log "this person got there because they tried using $" (or something like that)?

On your 403-forbidden.php page you can access the $_SERVER['HTTP_REFERER'] variable, to check to which URL the user tried to go, before ending on your error page.

You could log that into your database, or sent it to your mail adress.

More info on $_SERVER

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM