title: User Authentication in password grace period
body: <p>PHP Version 5.3.10 </p>
  
  <p>I'm using Apache on a Windows network and when I call $_SERVER['REMOTE_USER'] it works fine until the user enters the password expiry grace period (you have x days until your password expires) when all they see is this message:</p>
  
  <blockquote>
    <p><strong>Authorization Required</strong> The server could not verify that you are authorized to access the document requested. Either you supplied the
    wrong credentials (eg bad password), or your browser doesn’t
    understand how to supply the credentials required.</p>
  </blockquote>
  
  <p>Is there any way of catching this and presenting a more helpful message to the user?</p>
  
  <p><strong>Update</strong>
  Thanks Fred for the useful information. I added the following line to .htaccess</p>
  
  <pre><code>ErrorDocument 401     /401.php
  </code></pre>
  
  <p>and added 401.php to the same folder as .htaccess and I immediately got the following error when trying to access the site:</p>
  
  <blockquote>
    <p>Authorization Required This server could not verify that you are
    authorized to access the document requested. Either you supplied the
    wrong credentials (e.g., bad password), or your browser doesn't
    understand how to supply the credentials required.</p>
    
    <p>Additionally, a 401 Authorization Required error was encountered while
    trying to use an ErrorDocument to handle the request.</p>
  </blockquote>
  
  <p>As a test I also added</p>
  
  <pre><code>ErrorDocument 404     /404.php
  </code></pre>
  
  <p>and was correctly given the alternative page not found message.</p>
  
  <p>I'm not sure what you mean by "Then to catch the error, you would just use a function to write to file". Do you have an example? Following is the code I use to get the user's username:</p>
  
  <pre><code>$domain = $_SERVER['REMOTE_USER'];
  $domainarray = explode("\\",$domain);
  $username = strtolower ($domainarray[1]);
  </code></pre>