Replace htaccess popup with html form?

I have a password protected directory on my site using htaccess. When I enter a URL into a folder, I get a simple popup where I can enter my information. Things are good. But I really want to have an html / php / mySQL form that you can enter, instead of a popup. Is there any way to do this? NOTE. The directory I want to protect contains hundreds of files.

I know how to make a form, query the database, just want to replace the popup with an html form.

0


source to share


2 answers


One possible approach ...

Suppose you want to protect the "protected" directory.

Using .htaccess

, restrict access to this directory by putting

Options -Indexes

# Block External Access
deny from all

      

in a file .htaccess

in a "protected" directory.



Then, use a RewriteRule to catch all URLs going to the "protected" directory in the main file .htaccess

. For example:

RewriteEngine on
RewriteRule ^protected/(.*) accessprotected.php?url=$1

      

Typically a RewriteRule should intercept all URLs in a "protected" directory and pass them to the accessprotected.php page.

On the accessprotected.php page, check the login status.

if (isset($_SESSION['LoggedIn'])) { // or something like this
    /*
       Here, you should check what file type is being
       requested and handle this properly.
    */
} else {
    // put code for login form here
}

      

+1


source


You need to make sure that any landing page on the site will redirect you to the initial login page if the person hasn't signed up. This landing page must be HTML in order to be styled.



... Htaccess controls are an Apache feature and cannot be written using PHP or CSS or anything like that. They rely on built-in browser controls to bring back the default dialog.

0


source







All Articles