content.html

<!DOCTYPE html>
<html>
    <head>
        <title>Secret Page</title>
    </head>
    <body>
        <h1>Here it is!</h1>
        <p>I bet you are glad you can see this secret page.</p>
    </body>
</html>

rejection.html

<!DOCTYPE html>
<html>
    <head>
        <title>Rejected Page</title>
    </head>
    <body>
        <h1>Go Away!</h1>
        <p>You are not authorized to view this resource.</p>
    </body>
</html>

cd /var/www/html/php-books/php-and-mysql-web-development/chapter16/using-basic-authentication-with-apaches-htaccess-file-pag-374/
touch .htaccess
chmod 775 .htaccess

 AuthUserFile /var/www/.htpass
    AuthType Basic
    AuthName "Authorization Needed"
    AuthBasicProvider file
    Require valid-user
    ERRORDocument 401 /var/www/html/php-books/php-and-mysql-web-development/chapter16/using-basic-authentication-with-apaches-htaccess-file-pag-374/rejection.html

It should appear error 401 in the server the page is rejection.html

    You've said what should happen, but you don't say what is happening. Or if the book you're copying this from is any help at all in explaining anything.

    As @NogDog wrote in your previous question

    NogDog * Are you, in fact, testing this with a web server (as opposed to just calling the script directly on your computer via PHP)?

    And you replied

    bertrc I just calling the script directly on my computer via PHP

    Has this changed? Because you need a server to serve http.

      I have fedora 38 workstation with php,mariadb and apache installed.
      I code and run the code in the same computer

      English is not my mother tongue maybe I didn't explain well.
      Catalan

      it shows both pages with html but the .htaccess I thing is not working well
      it should show errordocument 401 when I choose rejection.html
      but I am not sure

      you and Nogdog always help me
      thank you

        Write a Reply...