...

View Full Version : How to log .htaccess authorization requests



moot
04-27-2011, 08:42 PM
For some silly reason I thought I was starting to understand this stuff... wrong...

This is my .htaccess

ErrorDocument 401 /cgi-bin/logins.php

RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} ^401$ [OR]
RewriteCond %{REQUEST_URI} ^
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},E=REMOTE_USER:%{ENV:REDIRECT_REMOTE_USER}]

<Files *>
AuthName "Log all access requests"
AuthUserFile /home/mydomain/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
Require valid-user
</Files>


This is the logins.php

<?php
define('LOGINS_LOG','/home/mydomain/logins.log');

$fp = fopen(LOGINS_LOG, 'a+');
$password=base64_decode(str_replace('Basic ','', $_SERVER['HTTP_AUTHORIZATION']));
fwrite($fp, "*".$password."*\r\n");
fclose($fp);

ob_start();
header("HTTP/1.1 401 Authorization Required",1);
header("Status: 401 Authorization Required",1);
echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head><title>401 Authorization Required</title></head><body>
<h1><center>Authorization Required</h1>
<p><center>This site could not verify that you
are authorized to access the document
requested.<br>Either you supplied the wrong
credentials (e.g., bad username/password combination),<br> or your
browser doesn\'t understand how to supply
the credentials required.</p></center>';
exit();
?>

The logins.log (first clicking cancel, second blank username/password, third wrong password.

**
*:*
*mytestr:failpass*

If I use the correct credentials nothing is written to the logins.log - what am I doing wrong?

mrglassworm
05-19-2011, 07:00 AM
Sounds very complicated, I thought it was one of those problems I faced. Hope someone chimes in soon to help you solve it.

mrglassworm
05-19-2011, 07:13 AM
Sounds very complicated, I thought it was one of those problems I faced. Hope someone chimes in soon to help you solve it.

moot
05-19-2011, 05:38 PM
Sounds very complicated,...

Must be...


... Hope someone chimes in soon to help you solve it.

So do I... like no one is interested... or knows... or doesn't want to share :rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum