Log in

View Full Version : .htaccess login question



PudgiPod
03-12-2007, 06:43 PM
Hello,

Right now I am using a perl script for logins on my website. I have an html login page with a form. Everyone uses the same login page, but depending on the password they type in, they are sent to the respective page declared in the perl script.

I just had some changes on my web hosting package and my .htaccess has been enabled. I wanted to use .htaccess for logins instead of the perl script.

All I know so far about .htaccess is that it requires a link to the specific page and then displays a popup asking for the username and password. Fine, but I want a master login page that acts as mentioned above. Is there a way to achieve this?

I've heard that Javascript can achieve an html login page, but I haven't found anything about a "master" login page.

Thank you.

BLiZZaRD
03-12-2007, 11:28 PM
Nothing I have found with .htaccess yet. I went looking for the same thing before.

The best I could do was using php to accomplish the "master log in"

here is an example page with such a log in. You can see the problems with too many different redirects :)



<?php
if($_POST['user']) {
if(($_POST['user'] == "John") && ($_POST['pass'] == "Doe")) header("Location: /JohnDoe/");
else if(($_POST['user'] == "Jane") && ($_POST['pass'] == "Doe")) header("Location: /JaneDoe");
else header("Location: wrong.htm");
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Log In</title>
</head>
<link rel="stylesheet" type="text/css" href="/css.css" />



<body>
<br><br>
<center>
<font size= "6">Please Log In Below:</font><br><br><br>
<form action="<?=$PHP_SELF?>" method="post">
<p>Username: <input type="text" name="user"/>
Password: <input type="password" name="pass"/>
<input type= "submit" value= "Log In"/></p>
</form>
</center>
</body>
</html>
<?php } ?>


Basically if Username == John, AND password == Doe, then they are redirected to folder named /JohnDoe/

Like wise for user == Jane and password == Doe

anything else will result in a redirection to page named wrong.htm

Hope the idea helps.

I am also working on a php log in that will ALSO prevent direct access to the files/folders through the URL. I have a working example, somewhere, I just have to find it again :)

PudgiPod
03-13-2007, 01:43 AM
That is basically what my perl script does. It works quite well, I just wanted to use .htaccess. Thanks for responding!