Advertisement
Guest User

Untitled

a guest
Mar 5th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <?php
  2. $host = 'localhost'; //Hostitel
  3. $db = 'freekeys'; //Nazev DB
  4. $user = 'FSK'; //Přihlašovací jméno
  5. $pass = 'Kokotik!1337'; //Přihlašovací heslo
  6. $charset = 'utf8';
  7.  
  8. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  9. $opt = [
  10. \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
  11. \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
  12. \PDO::ATTR_EMULATE_PREPARES => false,
  13. ];
  14. $pdo = new \PDO($dsn, $user, $pass, $opt);
  15.  
  16.  
  17.  
  18. /**
  19. *
  20. */
  21. class Callback
  22. {
  23.  
  24. function __construct(\PDO $pdo)
  25. {
  26. $this->conn = $pdo;
  27. }
  28.  
  29. public function addCallback($network, $currency, $snuid)
  30. {
  31. if(!$this->checksnuid($snuid))
  32. {
  33. $addCallback = $this->conn->prepare("INSERT INTO users (email, points, lastEvent, lastrewardDate) VALUES (:snuid, :currency, :network, NOW())");
  34. $addCallback->execute(array(
  35. 'snuid' => $snuid,
  36. 'currency' => $currency,
  37. "network" => $network
  38. ));
  39. //DEBUG
  40. if($addCallback)
  41. {
  42. echo ":OK";
  43. }
  44. }
  45. else
  46. {
  47. $this->update($network, $currency, $snuid);
  48. }
  49. }
  50.  
  51. public function checksnuid($snuid)
  52. {
  53. $checksnuid = $this->conn->prepare("SELECT email FROM users WHERE email=:snuid");
  54. $checksnuid->execute(array(
  55. 'snuid' => $snuid
  56. ));
  57.  
  58. $count = $checksnuid->rowCount();
  59.  
  60. if($count > 0)
  61. {
  62. return true;
  63. }
  64. else
  65. {
  66. return false;
  67. }
  68. }
  69.  
  70. public function update($network, $currency, $snuid)
  71. {
  72. $update = $this->conn->prepare("UPDATE users SET points = points + $currency, lastEvent=:network, lastrewardDate=NOW() WHERE email=:snuid");
  73. $update->execute(array(
  74. "network" => $network,
  75. 'snuid' => $snuid
  76. ));
  77. }
  78. }
  79.  
  80. $addCallback = new Callback($pdo);
  81. if(isset($_GET['snuid'])) {
  82. $currency = $_GET['currency'];
  83. $network = "tapjoy";
  84. $snuid = $_GET['snuid'];
  85. $addCallback->addCallback($network, $currency, $snuid);
  86. echo "200 OK";
  87. echo "<endora>";
  88. }
  89. else
  90. {
  91. echo "ERROR";
  92. }
  93.  
  94.  
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement