Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Login with htaccess through HTML/PHP

I'm working on a site with a directory that is protected with htaccess. I'd like to create a custom login page instead of relying on the browser default. Anyone have any experience with this?

I want to connect via a HTML form. Anyone think is it possible?

Thanks.

like image 700
Dev'Dev Avatar asked Nov 14 '13 13:11

Dev'Dev


1 Answers

Yes it's possible but you shouldn't use the htaccess digest authentication, you have to implement a custom Login Form in HTML & PHP.

You can implement something like this in PHP & htaccess

admin/.htaccess:

RewriteCond %{REQUEST_FILENAME} !check_auth.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* check_auth.php?file=$0 [QSA,L] # pass everything thru php

admin/check_auth.php:

$file = $_GET['file'];

if($_SESSION['user_authenticated']) {
  // please mind you need to add extra security checks here (see comments below)
   readfile($file); // if it's php include it. you may need to extend this code
}else{
  // bad auth error
}   

you can access directory files like this

check_auth.php?file=filename
like image 184
Hmmm Avatar answered Nov 13 '22 15:11

Hmmm