Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. public static function login()
  2. {
  3. // header("Content-Type: application/json");
  4. // header("Content-Type: text/javascript");
  5.  
  6. $response->msg = '';
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9.  
  10. $hashed = hash('md5', $password);
  11. $query = mysql_query("select * from tbl_user where username = '$username' and password = '$hashed'");
  12. $result = mysql_fetch_object($query);
  13.  
  14. if(mysql_num_rows($result) > 0)
  15. {
  16. $response->msg = 1;
  17. $response->username = $username;
  18.  
  19. // $response['msg'] = 1;
  20. // $response['username'] = $username;
  21.  
  22. echo json_encode($response);
  23. }
  24. else
  25. {
  26. // $response['msg'] = 0;
  27. $response->msg = 0;
  28. echo json_encode($username);
  29. }
  30. }
  31.  
  32. $("#btn_submit").click(function(){
  33.  
  34. var username = $("#txtusername").val();
  35. var password = $("#mypassword").val();
  36.  
  37. $.ajax({
  38. url: base_url + 'includes/main.php/login',
  39. data: { username: username, password: password },
  40. type: 'post',
  41. // async:false,
  42. dataType: 'json',
  43. success: function(data)
  44. {
  45. console.log(data);
  46. }
  47. });
  48. });
  49.  
  50.  
  51. // $('#btn_submit').click(function() {
  52. // var username = $("#txtusername").val();
  53. // var password = $("#mypassword").val();
  54. //
  55. // $.getJSON(base_url + 'includes/main.php/login',
  56. // { username: username, password: password },
  57. // function(json) {
  58. // console.log(json);
  59. // });
  60. // });
  61.  
  62.  
  63. // $('#btn_submit').click(function() {
  64. // var username = $("#txtusername").val();
  65. // var password = $("#mypassword").val();
  66. //
  67. // $.post(base_url + 'includes/main.php/login',
  68. // {username: username, password: password},
  69. // function(r) {
  70. // console.log(r);
  71. // }, "json");
  72. // });
  73.  
  74. url: base_url + 'includes/main.php/login',
  75.  
  76. $("#btn_submit").click(function(){
  77.  
  78. var username = $("#txtusername").val();
  79. var password = $("#mypassword").val();
  80.  
  81. $.ajax({
  82. url: base_url + 'includes/main.php',
  83. data: { action:'login', username: username, password: password },
  84. type: 'post',
  85. dataType: 'json',
  86. success: function(data)
  87. {
  88. console.log(data);
  89. }
  90. });
  91. return false;
  92. });
  93.  
  94. if(isset($_POST['action']) && $_POST['action'] == 'login') {
  95. login();
  96. }
  97.  
  98. function login()
  99. {
  100. header("Content-Type: application/json");
  101.  
  102. $response->msg = '';
  103. $username = $_POST['username'];
  104. $password = $_POST['password'];
  105.  
  106. // Do the rest ............
  107.  
  108. }
  109.  
  110. $.ajax({
  111. url: base_url + 'includes/main.php/login',
  112. data: { username: username, password: password },
  113. // async:false,
  114. type: 'post',
  115. dataType: 'json',
  116. success: function(data)
  117. {
  118. console.log(data);
  119. }
  120. });
  121.  
  122. $query = mysql_query("select * from tbl_user where username = $username and password = $hashed");
  123.  
  124. $query = mysql_query("select * from tbl_user where username = '$username' and password = '$hashed'");
  125.  
  126. $query = mysql_query("select * from tbl_user where username = $username and password = $hashed") or die('Query error');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement