Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2.  
  3. include("c:\dbconnect\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, kills, wins FROM users WHERE regkey='$rk'";
  82.  
  83. if ($stmt = $mysqli->prepare($query)) {
  84. $stmt->execute();
  85. $stmt->bind_result($username, $status, $email, $banned, $kills, $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 "}";
  93. }
  94.  
  95.  
  96. $stmt->close();
  97. }
  98.  
  99.  
  100. $mysqli->close();
  101. }
  102.  
  103. //////////////////////
  104. /////// Third Function Change State Of User Online/Offline
  105. //////////////////////
  106.  
  107. if($_GET["stuff"]=="u_status"){
  108.  
  109. $conn = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);
  110. // Check connection
  111. if ($conn->connect_error) {
  112. die("Connection failed: " . $conn->connect_error);
  113. }
  114. $status = $_GET["status"];
  115. $rk = $_GET["rk"];
  116.  
  117. $sql = "UPDATE users SET status='$status' WHERE regkey='$rk'";
  118.  
  119. if ($conn->query($sql) === TRUE) {
  120. echo "successfully";
  121. } else {
  122. echo "error" . $conn->error;
  123. }
  124.  
  125. $conn->close();
  126. }
  127.  
  128. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement