Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. <?php
  2. function loginCheck($conn){
  3.  
  4. session_start();
  5. //Check if login is achieved
  6. //Get variables from form
  7. $username=$_POST['namebox'];
  8. $password=$_POST['passbox'];
  9. $id=$_POST['idbox'];
  10. $stmt= $conn->prepare("SELECT * FROM users WHERE username =:username AND password=:password AND id=:id");
  11. $stmt->bindParam(':username',$username);
  12. $stmt->bindParam(':password',$password);
  13. $stmt->bindParam(':id',$id);
  14. $stmt->execute();
  15.  
  16. if(($stmt->rowCount()>0) ||($_SESSION['admin'])){
  17. echo "<p>Login successful</p>";
  18. $_SESSION['admin']=true;
  19. if ($id = 1 && $id =2) {
  20. header('Location: home.php');
  21. }
  22. else if ($id = 3) {
  23. header('Location: home.1.php');
  24. }
  25. else if ($id = 4) {
  26. header('Location: home.2.php');
  27. }
  28. else if ($id > 5) {
  29. header('Location: home.2.php');
  30. }
  31. return true;
  32. }
  33.  
  34. else {
  35. return false;
  36. }
  37.  
  38.  
  39. }//End of loginCheck
  40.  
  41. function loginCheck($conn){
  42.  
  43. session_start();
  44. //Check if login is achieved
  45. //Get variables from form
  46. $username=$_POST['namebox'];
  47. $password=$_POST['passbox'];
  48. $age=$_POST['agebox'];
  49. $stmt= $conn->prepare("SELECT * FROM users WHERE username =:username AND password=:password AND age=:age");
  50. $stmt->bindParam(':username',$username);
  51. $stmt->bindParam(':password',$password);
  52. $stmt->bindParam(':age',$age);
  53. $stmt->execute();
  54.  
  55. if(($stmt->rowCount()>0) ||($_SESSION['admin'])){
  56. echo "<p>Login successful</p>";
  57. $_SESSION['admin']=true;
  58. if ($age > 16) {
  59. header('Location: home.php');
  60. }
  61. else if ($age >11 && $age <15) {
  62. header('Location: home.1.php');
  63. }
  64. else if ($age >6 && $age <10) {
  65. header('Location: home.2.php');
  66. }
  67. else if ($age >2 && $age <5) {
  68. header('Location: home.3.php');
  69. }
  70.  
  71. return true;
  72. }
  73.  
  74. else {
  75. return false;
  76. }
  77.  
  78.  
  79. }//End of loginCheck
  80.  
  81. <?php
  82. require('functions.php');
  83. if(loginCheck($conn)){
  84. header('Location: home.php');
  85. }
  86.  
  87. else {
  88. require('loginheader.php');
  89. ?>
  90.  
  91. <form name="login" action="" method="POST">
  92. <label style="color: white; text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;" required><u>Name</u> : </label>
  93. <input type="text" name="namebox" length="20">
  94. <br/><br/>
  95. <label style="color: white; text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;" required><u>Password</u> : </label>
  96. <input type="password" name="passbox" length="20">
  97. <br/><br/>
  98. <label style="color: white; text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;" required><u>ID</u> : </label>
  99. <input type="number" name="idbox" length="20">
  100. <br/><br/>
  101. <input type="submit" class="button" name="submit">
  102. </form>
  103.  
  104. <?php
  105. require('footer.php');
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement