This may be more of an Apache question? But I'm using PHP code, so we'll see.
I have a directory ("/admin") that is password protected using .htaccess
In the root .htaccess file I have the following line:
ErrorDocument 401 /error.php?id=401
In the error.php file, I use the PHP function mail() to send me an email anytime someone reaches this page. I like knowing who is trying to login and where. The mail() function works perfectly EXCEPT that I get an email even when I login correctly.
So, it seems that the error 401 is triggered even on a successful login, only I am not redirected to the error.php page. However, the error.php page must be requested somehow since I get the email. Actually, I get two emails every time.
Any ideas?