PHP Login System Tutorial: Now, we will try to use phpsecuresite. In this practice, we build 3 file: form.html for login, login.php for validating, and secretpage.php is a protected page.
form.html
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form action="login.php" method="post">
Usename: <input type="text" name="username"><br>
Password: <input type="text" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
login.php
<?php
require ("./phpsecuresite/phpss/phpss.php");
$status = phpss_login($_POST["username"],$_POST["password"]);
switch($status){
case "phpss_login_allow":
header("location:secretpage.php");
exit();
break;
case "phpss_login_authfail":
print("Your username or password was wrong!");
break;
case "phpss_login_bruteforce_account_lock":
print("Locked, you are naughty!");
break;
case "phpss_login_bruteforce_iplock":
print("Your IP Locked, you are naughty!");
break;
default:
print("Not Known");
}
?>
secretpage.php
<html>
<head>
<title>Secret Page</title>
</head>
<body>
Wellcome!
</body>
</html>
Point your browser to http://localhost/test/phpsecuresite/form.html. Try wrong username or password. Then, click login.