Guest User

Untitled

a guest
Sep 7th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. Help with check login
  2. <?php
  3. ini_set('display_errors', 'On');
  4. error_reporting(E_ALL | E_STRICT);
  5.  
  6.  
  7.  
  8. $mysqli=new mysqli("localhost", "***", "***","***") ;
  9. if(!$mysqli){
  10. die("Database error");
  11. }
  12.  
  13.  
  14. function checklogin($username, $password){
  15. global $mysqli;
  16.  
  17.  
  18. $result = $mysqli->prepare("SELECT * FROM users WHERE username = ? and password=?");
  19. $result->bind_param("ss", $username, $password);
  20. $result->execute();
  21.  
  22. if($result != false){
  23.  
  24. $dbArray=$result->fetch();
  25.  
  26.  
  27. if(!$dbArray){
  28. echo '<p class="statusmsg">The username or password you entered is incorrect, or you haven't yet activated your account. Please try again.</p><br/><input class="submitButton" type="button" value="Retry" onClick="location.href='."'login.php'">";
  29. return;
  30. }
  31. $_SESSION['username']=$username;
  32.  
  33. if(isset($_POST['remember'])){
  34. setcookie("jmuser",$username,time()+60*60*24*356);
  35. setcookie("jmpass",$password ,time()+60*60*24*356);
  36. }
  37. echo'<p class="statusmsg"> You have successfully logged in. You will now be redirected to the homepage.</p>';
  38. redirect();
  39. }
  40.  
  41. else{
  42. echo'<p class="statusmsg"> The username or password you entered is incorrect. Please try again.</p><br/>input class="submitButton" type="button" value="Retry" onClick="location.href='."'login.php'">";
  43. return;
  44. }
  45. }
  46.  
  47. if(isset($_COOKIE['jmuser']) && isset($_COOKIE['jmpass'])){
  48.  
  49. $status=checkCookie($_COOKIE['jmuser'], $_COOKIE['jmpass']);
  50. if($status==true){
  51. echo '<p class="statusmsg"> Welcome back '.$_COOKIE['jmuser'].'. You will now be redirected to the homepage.</p>';
  52. sleep(5);
  53. redirect();
  54.  
  55. }
  56. }
  57.  
  58. else{
  59.  
  60.  
  61. if(isset($_POST['sublogin'])){
  62.  
  63. if(( strlen($_POST['user']) >0) && (strlen($_POST['pass']) >0)) {
  64.  
  65. checklogin($_POST['user'], $_POST['pass']);
  66.  
  67. }
  68. elseif((isset($_POST['user']) && empty($_POST['user'])) || (isset($_POST['pass']) && empty($_POST['pass']))){
  69.  
  70. echo '<p class="statusmsg">You didn't fill in the required fields.</p><br/><input class="submitButton" type="button" value="Retry" onClick="location.href='."'login.php'">";
  71.  
  72. }
  73. }
  74. else{
  75.  
  76. echo '<p class="statusmsg">You came here by mistake, didn't you?</p>';
  77.  
  78. }
  79.  
  80.  
  81. }
  82.  
  83. <?php
  84. if(isset($_GET['url'])){
  85.  
  86. function redirect() {
  87. header('location:'.$_GET['url']);
  88. }
  89. }
  90. else {
  91. function redirect() {
  92. header('location: index.php');
  93. }
  94. }
  95.  
  96. ?>
  97.  
  98. setcookie("jmuser",$username,time()+60*60*24*356);
  99. setcookie("jmpass",$password ,time()+60*60*24*356);
Add Comment
Please, Sign In to add comment