Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- date_default_timezone_set('America/Los_Angeles');
- /*
- @@@@
- @@ Author: Desugrace
- @@ Year: 2011
- @@ Description: Gaming Ladder Class
- @@ Version: 1
- @@
- @@@@
- */
- //example
- //
- //$GL = new GL;
- //($GL->Add_Team('TEST') != 00000) ? 'error' : 'added team';
- //($GL->Exists('test' , 'user') > 0) ? 'user already taken' : 'user is available';
- //foreach($GL->Grab_Teams as $team) { echo $team['name']; echo $team['rank']; }
- class GL {
- protected $pass_key = 'a89282'; //random salt for passwords, don't change,after someone has registered..
- public $pdo;
- public $pdo_statement;
- public $host = 'localhost'; //change this
- public $database = 'gl'; //change this
- public $username = 'root'; //change this
- protected $password = ''; //change this
- public $user_table = 'users'; //change this only if you want/have to change the default name of the table
- public $team_table = 'teams'; //change this only if you want/have to change the default name of the table
- public function __construct() {
- try {
- $this->pdo = new PDO("mysql:host=$this->host;dbname=$this->database", $this->username, $this->password);
- } Catch (Exception $x) {
- exit('Something is wrong with the sql configuration:<br> ' . $x->getMessage());
- }
- }
- public function Grab_Teams() {
- $this->pdo_statement = $this->pdo->query('SELECT * FROM teams');
- return $this->pdo_statement->fetchALL(PDO::FETCH_ASSOC);
- }
- public function Grab_Users() {
- $this->pdo_statement = $this->pdo->query('Select * FROM users');
- return $this->pdo_statement->fetchALL(PDO::FETCH_ASSOC);
- }
- public function Register($username=null, $password=null, $email=null) {
- $password = MD5($password . $this->pass_key);
- if ($this->Exists($username, 'user') < 0) {
- $this->pdo_statement = $this->pdo->prepare("INSERT into $this->user_table(`username`,`password`,`email`) VALUES('$username','$password','$email')");
- $this->pdo_statement->execute();
- } else {
- return false;
- }
- }
- public function Add_Team($name) {
- $this->pdo_statement = $this->pdo->prepare("INSERT into $this->team_table(`name`) VALUES ('$name')");
- $this->pdo_statement->execute();
- return $this->pdo_statement->errorCode();
- }
- public function Delete_User($username) {
- $this->pdo->query("DELETE from $this->user_table WHERE `username`='$username' ");
- return $this->pdo->errorCode();
- }
- public function Login($username=null, $password=null) {
- $password = MD5($password . $this->pass_key);
- $IP = $_SERVER['REMOTE_ADDR'];
- $last_accessed = date('d-m-y H:i:s', time());
- $this->pdo_statement = $this->pdo->prepare("SELECT `username`, `password` FROM $this->team_table WHERE `username`='$username' AND `password'='$password' ");
- $this->pdo_statement->execute();
- if ($this->pdo_statement->rowCount() >= 1) {
- $this->pdo->query("UPDATE $this->user_table SET `last_access` = '$last_accessed' AND `last_ip` = '$IP' WHERE `username`='$username' ");
- $_SESSION['xl'] = base64_encode($username);
- $_SESSION['xp'] = base64_encode($IP);
- } else {
- return false;
- }
- }
- public function Logged_in() {
- if (isset($_SESSION['username'])) {
- if ($_SERVER['REMOTE_ADDR'] = base64_encode($_SESSION['x243']) && $this->Exists(base64_encode($_SESSION['x242']), 'user')) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- public function Exists($value = null, $type= null) {
- switch ($type) {
- case 'team':
- $this->pdo_statement = $this->pdo->prepare("SELECT * FROM $this->team_table WHERE `name`='$value'");
- $this->pdo_statement->execute();
- return $this->pdo_statement->rowCount();
- break;
- case 'user':
- $this->pdo_statement = $this->pdo->prepare("SELECT * FROM $this->user_table WHERE `username`= '$value'");
- $this->pdo_statement->execute();
- return $this->pdo_statement->rowCount();
- break;
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment