Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. <?php
  2.  
  3. include("dbconnect.php");
  4.  
  5.  
  6. /////// First Function To Get User Data For Login
  7.  
  8.  
  9.  
  10. if($_GET["stuff"]=="login"){
  11.  
  12. $mysqli = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);
  13.  
  14. if (mysqli_connect_errno()) {
  15. printf("Connect failed: %s\n", mysqli_connect_error());
  16. exit();
  17. }
  18.  
  19.  
  20. /////// Need to Grab Username And Password
  21.  
  22.  
  23.  
  24. $username = $_GET["user"];
  25. $password = $_GET["password"];
  26.  
  27. // create a prepared statement
  28. $stmt = mysqli_prepare($mysqli, "SELECT username, password, regkey, banned FROM users WHERE username='$username'");
  29.  
  30. // bind parameters
  31. mysqli_stmt_bind_param($stmt, 's', $username);
  32.  
  33. // execute query
  34. mysqli_stmt_execute($stmt);
  35.  
  36. // bind result variables
  37. mysqli_stmt_bind_result($stmt, $username, $hashed_password, $regkey, $banned);
  38.  
  39. // fetch value
  40. mysqli_stmt_fetch($stmt);
  41.  
  42. if(password_verify($password, $hashed_password)){
  43. echo json_encode(array('result' => 'success', 'regkey' => $regkey, 'banned' => $banned));
  44. }else{
  45. // incorrect password
  46. }
  47.  
  48. mysqli_stmt_close($stmt);
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. $mysqli->close();
  57.  
  58. }
  59.  
  60.  
  61. //////////////////////
  62. /////// Second Function Getting The User Information
  63. //////////////////////
  64.  
  65. if($_GET["stuff"]=="userinfo"){
  66.  
  67. $mysqli = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);
  68.  
  69. if (mysqli_connect_errno()) {
  70. printf("Connect failed: %s\n", mysqli_connect_error());
  71. exit();
  72. }
  73.  
  74. //////// Gets the RegKey which is Unique To The User
  75.  
  76. $rk = $_GET["rk"];
  77.  
  78.  
  79.  
  80.  
  81. $query = "SELECT username, status, email, banned, gold, wins FROM users WHERE regkey='$rk'";
  82.  
  83. if ($stmt = $mysqli->prepare($query)) {
  84. $stmt->execute();
  85. $stmt->bind_result($username, $status, $email, $banned, $gold, $wins);
  86. while ($stmt->fetch()) {
  87. echo "{";
  88. echo '"status": "' . $status . '",';
  89. echo '"username": "' . $username . '",';
  90. echo '"email": "' . $email . '",';
  91. echo '"banned": "' . $banned . '",';
  92. echo '"gold": "' . $gold . '",';
  93. echo '"wins": "' . $wins . '"';
  94. echo "}";
  95. }
  96.  
  97.  
  98. $stmt->close();
  99. }
  100.  
  101.  
  102. $mysqli->close();
  103. }
  104.  
  105. //////////////////////
  106. /////// Third Function Change State Of User Online/Offline
  107. //////////////////////
  108.  
  109. if($_GET["stuff"]=="u_status"){
  110.  
  111. $conn = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);
  112. // Check connection
  113. if ($conn->connect_error) {
  114. die("Connection failed: " . $conn->connect_error);
  115. }
  116. $status = $_GET["status"];
  117. $rk = $_GET["rk"];
  118.  
  119. $sql = "UPDATE users SET status='$status' WHERE regkey='$rk'";
  120.  
  121. if ($conn->query($sql) === TRUE) {
  122. echo "successfully";
  123. } else {
  124. echo "error" . $conn->error;
  125. }
  126.  
  127. $conn->close();
  128. }
  129.  
  130. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement