Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>PHP Project: Login</title>
  4. </head>
  5. <body>
  6.  
  7. <?php
  8.  
  9. //Error reporting
  10. ini_set('display_errors', '1');
  11. error_reporting(E_ALL);
  12.  
  13. //Start the session
  14. session_start();
  15.  
  16. //Session Variables
  17. $_SESSION['username'] = $_POST["username"];
  18. $_SESSION['password'] = $_POST["password"];
  19.  
  20. //Validation Function
  21. function validate_input($val_user, $val_pass)
  22. {
  23.     if ($val_user == null && $val_pass == null)
  24.     {
  25.         //No username or password were entered
  26.         return 1;
  27.     }
  28.     else
  29.     {  
  30.         if ($val_user == null)
  31.         {
  32.             //No username entered
  33.             return 2;
  34.         }
  35.         else
  36.         {
  37.             if ($val_pass == null)
  38.             {
  39.                 //No password was entered
  40.                 return 3;
  41.             }
  42.             else
  43.             {
  44.                 //User input was validated successfully
  45.                 return 0;
  46.             }
  47.         }
  48.     }
  49. }
  50.  
  51. switch (validate_input($_SESSION['username'], $_SESSION['password']))
  52. {
  53.     case 0:
  54.     {
  55.         //User input was validated successfully            
  56.         echo "Success! :>";
  57.         //do stuff
  58.         break;
  59.     }
  60.     case 1:
  61.     {
  62.         //No username or password were entered
  63.         echo "You did not enter a username OR password";
  64.         break;
  65.     }
  66.     case 2:
  67.     {
  68.         //No password was entered
  69.         echo "You did not enter a username";
  70.         break;
  71.     }
  72.     case 3:
  73.     {
  74.         //No password was entered
  75.         echo "You did not enter a password";
  76.         break;
  77.     }
  78. }
  79.  
  80. ?>
  81.  
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement