Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to log .htaccess authorization requests

    For some silly reason I thought I was starting to understand this stuff... wrong...

    This is my .htaccess
    Code:
    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
    Code:
    <?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?
    You can lead a horse to water, but you can't make 'em think...

  • #2
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sounds very complicated, I thought it was one of those problems I faced. Hope someone chimes in soon to help you solve it.

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sounds very complicated, I thought it was one of those problems I faced. Hope someone chimes in soon to help you solve it.

  • #4
    New Coder
    Join Date
    Mar 2011
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mrglassworm View Post
    Sounds very complicated,...
    Must be...

    Quote Originally Posted by mrglassworm View Post
    ... 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
    You can lead a horse to water, but you can't make 'em think...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •