Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>PHP Project: Login</title>
- </head>
- <body>
- <?php
- //Error reporting
- ini_set('display_errors', '1');
- error_reporting(E_ALL);
- //Start the session
- session_start();
- //Session Variables
- $_SESSION['username'] = $_POST["username"];
- $_SESSION['password'] = $_POST["password"];
- //Validation Function
- function validate_input($val_user, $val_pass)
- {
- if ($val_user == null && $val_pass == null)
- {
- //No username or password were entered
- return 1;
- }
- else
- {
- if ($val_user == null)
- {
- //No username entered
- return 2;
- }
- else
- {
- if ($val_pass == null)
- {
- //No password was entered
- return 3;
- }
- else
- {
- //User input was validated successfully
- return 0;
- }
- }
- }
- }
- switch (validate_input($_SESSION['username'], $_SESSION['password']))
- {
- case 0:
- {
- //User input was validated successfully
- echo "Success! :>";
- //do stuff
- break;
- }
- case 1:
- {
- //No username or password were entered
- echo "You did not enter a username OR password";
- break;
- }
- case 2:
- {
- //No password was entered
- echo "You did not enter a username";
- break;
- }
- case 3:
- {
- //No password was entered
- echo "You did not enter a password";
- break;
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement