Zend - The PHP Company




Authentication

Add Code


Super Simple Password Protect  

Type: code fragment
Added by: deathdog
Entered: 28/09/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 15461
I've found the need to password protect a few webpages and didn't feel like setting up a "real" authentication scheme. This is pretty cheesy, but good for someone who has a webpage and wants to make the information only available to a select few.


<HTML>
<HEAD>
<TITLE>Some Title</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<center><img src="somecoolimage.jpg"></center>

<?php
$login 
foo;
$password bar;

if (isset(
$form[login]) && isset($form[password])){
    if ((
$login == $form[login]) && ($password == $form[password])){

print(
"Put all the HTML here");

}else{
    print(
"<h3>Invalid Login</h3><br><br><FORM method=post>");
    print(
"<table>
    <tr>
    <td><b>Login</b></td>
        <td><b>Password</b></td>
    </tr>
    <tr>
        <td><input type=text name='form[login]'></td>
        <td><input type=password name='form[password]'></td>    
    </tr>
</table>
<br><br><input type=submit value=Login></form>"
);
}
}else{
    print(
"<h3>&nbsp</h3><br><br>

<FORM method=post><table>
    <tr>
    <td><b>Login</b></td>
        <td><b>Password</b></td>
    </tr>
    <tr>
        <td><input type=text name='form[login]'></td>
        <td><input type=password name='form[password]'></td>    
    </tr>
</table>
<br><br><input type=submit value=Login></form>"
);
}
?>
</BODY>
</HTML>


Usage Example


Example?


Rate This Script





Search



This Category All Categories