Basic PHP Authentication Form Tutorial
This is an extremely simple PHP authentication "script" that I threw together to help remind myself a couple PHP related things. If it is any use to anyone, great. There are many more complete tutorials posted for authenticating in PHP / HTML. Many things are intentionally left out, including database backend, security, and scripting. This is intended to be for beginners and my future reference.
Here is the extremely simple PHP / HTML:
<html>
<body>
<form name="login" method="post" action=<?php echo $_SERVER['PHP_SELF']?> >
<input type="input" name="user" /><br>
<input type="password" name="pass" /><br>
<input type="submit" value="Login" />
</form>
<?php
if ((isset($_POST['user'])) && (isset($_POST['pass']))) {
$username = $_POST['user'];
$password = $_POST['pass'];
if (($username == "hello") && ($password == "password")) {
echo "Authentication Succeeded";
}
else {
echo "Authentication Failed";
}
}
?>
</body>
</html>
The PHP code simply looks for the "user" and "pass" variables to be set via the form. A "valid" log in is a user name of "hello" and a password of "password". If they are set, and the user and password are correct we output a succeeded message, otherwise a Failed message is displayed.
