Guest User

Untitled

a guest
Dec 11th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. date_default_timezone_set('America/Los_Angeles');
  5. /*
  6. @@@@
  7. @@ Author: Desugrace
  8. @@ Year: 2011
  9. @@ Description: Gaming Ladder Class
  10. @@ Version: 1
  11. @@
  12. @@@@
  13. */
  14.  
  15. //example
  16. //
  17. //$GL = new GL;
  18. //($GL->Add_Team('TEST') != 00000) ? 'error' : 'added team';
  19. //($GL->Exists('test' , 'user') > 0) ? 'user already taken' : 'user is available';
  20. //foreach($GL->Grab_Teams as $team) { echo $team['name']; echo $team['rank']; }
  21. class GL {
  22.  
  23. protected $pass_key = 'a89282'; //random salt for passwords, don't change,after someone has registered..
  24. public $pdo;
  25. public $pdo_statement;
  26. public $host = 'localhost'; //change this
  27. public $database = 'gl'; //change this
  28. public $username = 'root'; //change this
  29. protected $password = ''; //change this
  30. public $user_table = 'users'; //change this only if you want/have to change the default name of the table
  31. public $team_table = 'teams'; //change this only if you want/have to change the default name of the table
  32.  
  33. public function __construct() {
  34. try {
  35. $this->pdo = new PDO("mysql:host=$this->host;dbname=$this->database", $this->username, $this->password);
  36. } Catch (Exception $x) {
  37. exit('Something is wrong with the sql configuration:<br> ' . $x->getMessage());
  38. }
  39. }
  40.  
  41. public function Grab_Teams() {
  42. $this->pdo_statement = $this->pdo->query('SELECT * FROM teams');
  43. return $this->pdo_statement->fetchALL(PDO::FETCH_ASSOC);
  44. }
  45.  
  46. public function Grab_Users() {
  47. $this->pdo_statement = $this->pdo->query('Select * FROM users');
  48. return $this->pdo_statement->fetchALL(PDO::FETCH_ASSOC);
  49. }
  50.  
  51. public function Register($username=null, $password=null, $email=null) {
  52. $password = MD5($password . $this->pass_key);
  53. if ($this->Exists($username, 'user') < 0) {
  54. $this->pdo_statement = $this->pdo->prepare("INSERT into $this->user_table(`username`,`password`,`email`) VALUES('$username','$password','$email')");
  55. $this->pdo_statement->execute();
  56.  
  57. } else {
  58. return false;
  59. }
  60. }
  61. public function Add_Team($name) {
  62. $this->pdo_statement = $this->pdo->prepare("INSERT into $this->team_table(`name`) VALUES ('$name')");
  63. $this->pdo_statement->execute();
  64. return $this->pdo_statement->errorCode();
  65. }
  66.  
  67. public function Delete_User($username) {
  68. $this->pdo->query("DELETE from $this->user_table WHERE `username`='$username' ");
  69. return $this->pdo->errorCode();
  70.  
  71.  
  72. }
  73.  
  74. public function Login($username=null, $password=null) {
  75. $password = MD5($password . $this->pass_key);
  76. $IP = $_SERVER['REMOTE_ADDR'];
  77. $last_accessed = date('d-m-y H:i:s', time());
  78. $this->pdo_statement = $this->pdo->prepare("SELECT `username`, `password` FROM $this->team_table WHERE `username`='$username' AND `password'='$password' ");
  79. $this->pdo_statement->execute();
  80. if ($this->pdo_statement->rowCount() >= 1) {
  81. $this->pdo->query("UPDATE $this->user_table SET `last_access` = '$last_accessed' AND `last_ip` = '$IP' WHERE `username`='$username' ");
  82. $_SESSION['xl'] = base64_encode($username);
  83. $_SESSION['xp'] = base64_encode($IP);
  84. } else {
  85. return false;
  86. }
  87. }
  88.  
  89. public function Logged_in() {
  90.  
  91. if (isset($_SESSION['username'])) {
  92. if ($_SERVER['REMOTE_ADDR'] = base64_encode($_SESSION['x243']) && $this->Exists(base64_encode($_SESSION['x242']), 'user')) {
  93. return true;
  94. } else {
  95. return false;
  96. }
  97. } else {
  98. return false;
  99. }
  100. }
  101.  
  102. public function Exists($value = null, $type= null) {
  103. switch ($type) {
  104. case 'team':
  105. $this->pdo_statement = $this->pdo->prepare("SELECT * FROM $this->team_table WHERE `name`='$value'");
  106. $this->pdo_statement->execute();
  107. return $this->pdo_statement->rowCount();
  108.  
  109. break;
  110. case 'user':
  111. $this->pdo_statement = $this->pdo->prepare("SELECT * FROM $this->user_table WHERE `username`= '$value'");
  112. $this->pdo_statement->execute();
  113. return $this->pdo_statement->rowCount();
  114.  
  115. break;
  116. }
  117. }
  118.  
  119. }
  120.  
  121. ?>
Add Comment
Please, Sign In to add comment