This script is just the implementation of previous post which explains how to retrieve information from user through html forms. We will be needing two files, first the login.html file to display our HTML form and the other file login.php to process the input provided by the user. login.php actually processes and decides if the login details provided by the user are correct or not. If the details are correct it shows a “Login Successful” message. There is nothing extraordinary about the code in login.php. It just fetches the values from the form and checks if they are correct using an IF statement.
login.html:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Login Page</title> </head> <body> <form action = "login.php" method = "post"> User: <input type = "text" name = "user"> Password: <input type="password" name = "pass""> <input type = "submit" value ="Login"> </form> </body> </html> |
login.php:
|
1 2 3 4 5 6 7 8 9 |
<?php $user = $_POST['user']; $pass = $_POST['pass']; if ($user == 'Vlad' && $pass == '1234'){ echo 'Login Successful!'; }else { echo 'Wrong username/password. Please try again.'; } ?> |
Vlad
Latest posts by Vlad (see all)
- Code jam “Tic-Tac-Toe-Tomek” solution in java - April 19, 2013
- Code jam “Minimum Scalar product” solution in java - March 18, 2013
- Code jam Store Credit solution in java - March 10, 2013