Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1.  
  2. <?php
  3. ////GET IP
  4. function getUserIP()
  5. {
  6. if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
  7. $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
  8. $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
  9. }
  10. $client = @$_SERVER['HTTP_CLIENT_IP'];
  11. $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
  12. $remote = $_SERVER['REMOTE_ADDR'];
  13.  
  14. if(filter_var($client, FILTER_VALIDATE_IP))
  15. {
  16. $ip = $client;
  17. }
  18. elseif(filter_var($forward, FILTER_VALIDATE_IP))
  19. {
  20. $ip = $forward;
  21. }
  22. else
  23. {
  24. $ip = $remote;
  25. }
  26.  
  27. return $ip;
  28. }
  29.  
  30. $user_ip = getUserIP();
  31.  
  32. $ip = $_SERVER['REMOTE_ADDR'];
  33. $details = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
  34. $usercountry = $details->country; //
  35. ////ab hier schreiben
  36. date_default_timezone_set('Europe/Berlin');
  37. $date = date('d.m.y');
  38. $time = date('H:i:s');
  39. $servername = "localhost";
  40. $user = "root";
  41. $pw =
  42. $db = "unrealengine";
  43.  
  44. $con = new mysqli($servername, $user, $pw, $db);
  45.  
  46. if($con->connect_error) {
  47. die("keine connection lmao".$con->connect_error);
  48. }
  49.  
  50. $clientauthkey = mysqli_real_escape_string($con, $_GET["authkey"]);
  51. $clientusername = mysqli_real_escape_string($con, $_GET["username"]);
  52. $isregisterevent = mysqli_real_escape_string($con, $_GET["reg"]);
  53. $clientpassword = mysqli_real_escape_string($con, $_GET["password"]);
  54. $email = mysqli_real_escape_string($con, $_GET["email"]);
  55. //für richtig krasse noobs
  56. if ($_GET["key"] === "lmao"){
  57. }
  58. else {
  59. die("connection refused.");
  60. }
  61.  
  62. //prüft ob die Anfrage für ein Reg konzepiert ist
  63. if($isregisterevent === "yes"){
  64. $sql = "SELECT * FROM `users` WHERE `username` LIKE '$clientusername'";
  65. $result = $con->query($sql);
  66. //prüft ob spieler schon regestriert ist
  67. if($result->num_rows === 0){
  68. $sql = $con->prepare("INSERT INTO `users` (`id`, `username`, `password`, `authkey`, `role`, `email`, `lastallowedip`) VALUES (NULL, ?, ?, ?, 'player', ?, '$user_ip am $date um $time in $usercountry')");
  69. $sql->bind_param("ssss", $clientusername, $clientpassword, $clientauthkey, $email);
  70. $sql->execute();
  71. //wird noch gemacht wird aber genau so aufgebaut werden (wird geshashed und salted mit sha512/bcrypt und veri. mit password verify :9)
  72. echo "You have been registered! Check your Emails to enter your password";
  73. $sql->close();
  74. }
  75. else{
  76. echo "already registered";
  77. }
  78. }
  79. else {
  80. $sql = "SELECT * FROM `users` WHERE `username` LIKE '$clientusername'";
  81. $result = $con->query($sql);
  82. if ($result->num_rows > 0) {
  83. while($row = $result->fetch_assoc()){
  84. $serverpassword = $row["password"];
  85. $serverauthkey = $row["authkey"];
  86. }
  87. }
  88. else {
  89. echo "account not found";
  90. }
  91. echo $sql->error;
  92. if ($serverpassword === $clientpassword){
  93. echo "authkey: " . $serverauthkey;
  94. $sql = "UPDATE `users` SET `lastallowedip` = '$user_ip am $date um $time in $usercountry' WHERE `username` = '$clientusername'";
  95. $con->query($sql);
  96. }
  97. else{
  98. echo "wrong password $usercountry";
  99. $sql = "UPDATE `users` SET `lastrefusedip` = '$user_ip am $date um $time in $usercountry' WHERE `username` = '$clientusername'";
  100. $con->query($sql);
  101. }
  102. }
  103. $con->close();
  104. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement