Comments
No comments yet. You can be the first!
Posted by: fay
This is useful for anyone who'd like to add a login form to any php page.
< ? include "access.php"; ?>
(remove the space before the question mark)
The crentials can be edited in the access.php file, by changing the values of $ADMIN_USER and $ADMIN_PASSWORD. This useful script requires no database, and no big tweaking to the code on your pages.
Please save this as access.php
<?
session_start();
$ADMIN_USER = "user";
$ADMIN_PASSWORD = "password";
if(!$_SESSION['authenticated'])
if($_POST['loginbutton']) {
$inputuser = $_POST['input_user'];
$inputpassword = $_POST['input_password'];
if(!strcmp($inputuser ,$ADMIN_USER) && !strcmp($inputpassword,$ADMIN_PASSWORD)) {
$_SESSION['authenticated'] = 1;
header("Location:".$_SERVER[PHP_SELF]);
}
else
displayform(1);
}
else
displayform(0);
function displayform($error) {
echo "<html><head><title>Please login</title></head><body><style>body,td,input { font-family: verdana; font-size: 8pt; }</style>";
if($error) echo "<p><b>Wrong credentials.</b></p>";
echo "<form action=\"\" method=\"post\"><table width='400' border=0><tr><td width='100'>username:</td>";
echo "<td><input type='text' name='input_user'></td></tr><tr><td>password:</td><td><input type='password' name='input_password'></td></tr>";
echo "<tr><td colspan='2'><input type='Submit' value='Login»' name='loginbutton'></td></tr></table></form></body></html>";
exit;
}
?>
No comments yet. You can be the first!