Guest User

Untitled

a guest
Apr 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. <?php
  2. $username = "";
  3. $ID = "";
  4. $errorMessage = "";
  5.  
  6. if (isset($_POST['submit'])) { //submit button has been clicked
  7. $username = $_POST['username']; //read in the value the user has entered for the username
  8. $username = htmlspecialchars($username); //prevent cross site scripting errors
  9. $username = strip_tags($username); //prevent cross site scripting errors
  10. $username = trim($username); //trim any whitespaces in the input value
  11.  
  12.  
  13.  
  14.  
  15.  
  16. $ID = $_POST['ID'];
  17. $ID = htmlspecialchars($ID);
  18. $ID = strip_tags($ID);
  19. $ID = trim($ID);
  20.  
  21. session_start(); //start a session
  22.  
  23. $user_name = "root"; //default username for MySQL
  24. $password = ""; //default password for MySQL
  25. $database = "myapplication"; //name of db you created
  26. $server = "127.0.0.1"; //IP address of the database
  27.  
  28. $db_handle = mysql_connect($server, $user_name, $password);
  29. $db_found = mysql_select_db($database);
  30.  
  31. if(!$db_found) {
  32. print"Daabase NOT found" ;
  33.  
  34. }
  35. else {
  36. $SQL = "SELECT * FROM login WHERE uname = "."'".$username."'". " AND ID = "."'"."$ID"."'";
  37. $result = mysql_query($SQL);
  38. $num_rows = mysql_num_rows($result);
  39. if ($num_rows > 0) {
  40. $_SESSION['login']="1"; //set the value of the 'login' session variable to '1
  41. $_SESSION['username']="Joe";
  42. header('Location: topSecret.php'); //redirect the user to topSecret.php page
  43. }
  44. }
  45. mysql_close($db_handle);
  46.  
  47. /*
  48. if($username=="Joe" && $ID==1234) { //valid user
  49. // store session data
  50. $_SESSION['login']="1"; //set the value of the 'login' session variable to '1
  51. $_SESSION['username']="Joe";
  52. header('Location: topSecret.php'); //redirect the user to topSecret.php page
  53. } else {
  54. session_start(); //start
  55. $errorMessage = "Login Unsuccessful";
  56. $_SESSION['error']=$errorMessage; //sets the value of the 'errorMessage' session variable
  57. $_SESSION['login'] = ""; //set the value of the 'login' session variable to ''
  58. //redirect to login page & send error message
  59. header('Location: loginForm.php'); //redirect the user to the login page
  60.  
  61. }
  62. */
  63. }
  64. ?>
Add Comment
Please, Sign In to add comment