Guest User

Untitled

a guest
Feb 13th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. [13-Feb-2018 11:01:44 America/New_York] PHP Notice: Undefined variable: email in /home/beaspsaq/imgs/php/login.php on line 36
  2. [13-Feb-2018 11:01:44 America/New_York] PHP Notice: Undefined variable: con in /home/beaspsaq/imgs/php/login.php on line 37
  3. [13-Feb-2018 11:01:44 America/New_York] PHP Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/beaspsaq/imgs/php/login.php on line 37
  4. [13-Feb-2018 11:01:44 America/New_York] PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/beaspsaq/imgs/php/login.php on line 38
  5. [13-Feb-2018 11:01:44 America/New_York] PHP Notice: Undefined variable: con in /home/beaspsaq/imgs/php/login.php on line 81
  6. [13-Feb-2018 11:01:44 America/New_York] PHP Warning: mysqli_close() expects parameter 1 to be mysqli, null given in /home/beaspsaq/imgs/php/login.php on line 81
  7. [13-Feb-2018 11:01:45 America/New_York] PHP Notice: Undefined index: remember_me in /home/beaspsaq/imgs/php/login.php on line 16
  8. [13-Feb-2018 11:01:45 America/New_York] PHP Warning: mysqli_connect() expects parameter 5 to be long, string given in /home/beaspsaq/imgs/php/login.php on line 28
  9.  
  10. <?php
  11. session_start();
  12.  
  13. if(isset($_SESSION["id"]) || isset($_COOKIE["id"]))
  14. {
  15. header("Location: dashboard.php");
  16. }
  17.  
  18. if(isset($_POST["login"]))
  19. {
  20. //Gather input variables
  21. $email = isset($_POST['email']) ? $_POST['email'] : '';
  22. $password = isset($_POST["password"]) ? $_POST['password'] : '';
  23. //Hash password as pasword should be hashed in database for security reasons. See md5 hashing
  24. $hash_password = md5($password);
  25. $remember_me = $_POST["remember_me"];
  26.  
  27.  
  28.  
  29.  
  30. //Connect to Database
  31. $host="-";
  32. $username="-";
  33. $password="-";
  34. $db_name="-";
  35. $tbl_name="-";
  36.  
  37. $con = mysqli_connect("-","-","-","-","-")or die("cannot connect: " . mysqli_connect_error());
  38. mysqli_select_db("$db_name")or die("cannot select DB");
  39. }
  40.  
  41.  
  42.  
  43.  
  44. //Check database to see if email registered to DB
  45. $sql = "SELECT id FROM users WHERE email='$email' LIMIT 1";
  46. $query = mysqli_query($con, $sql);
  47. $count_users = mysqli_num_rows($query);
  48.  
  49. if($count_users == 1)
  50. {
  51.  
  52. //Retrieve user details to perform login
  53. $sql = "SELECT * FROM users WHERE email='$email' LIMIT 1";
  54. $query = mysqli_query($con, $sql);
  55. while($row = mysqli_fetch_array($query))
  56. {
  57. $user_id = $row["id"];
  58. $user_password = $row["password"];
  59.  
  60. }
  61.  
  62.  
  63. if($hash_password == $user_password)
  64. {
  65. if($remember_me == 1)
  66. {
  67. //Set Cookie
  68. $cookie_name = "id";
  69. setcookie($cookie_name, $user_id, time() + (86400 * 30), "/");
  70.  
  71. header("Location: dashboard.php");
  72. }
  73. else
  74. {
  75. //Set Session
  76. $_SESSION["id"] = $user_id;
  77. header("Location: dashboard.php");
  78. }
  79. }
  80. else
  81. {
  82. $error = '<p class="error">Password incorrect.</p>';
  83. }
  84. }
  85. else
  86. {
  87. $error = '<p class="error">Email address not registered.</p>';
  88. }
  89.  
  90. mysqli_close($con);
  91. ?>
Add Comment
Please, Sign In to add comment