Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Session Start
- session_name('client');
- session_start();
- // Config MySQL
- require_once('DB.config.php');
- $PDO = (new DB())->pdo;
- // Function Logged
- $logged = NULL;
- if(!empty($_SESSION['logged'])) {
- $logged = $_SESSION['logged'];
- }
- // Function login
- class User {
- public function __construct() {
- global $PDO;
- if(!empty($_SESSION['uid']) && !empty($_SESSION['user'])) {
- $this->userData = $PDO->prepare('SELECT * FROM servers WHERE id=:id LIMIT 1');
- $this->userData->bindValue('id', $_SESSION['uid']);
- $this->userData->execute();
- $this->userData = $this->userData->fetchObject();
- if(empty($this->userData)) {
- $_SESSION['logged'] = "no-logged";
- }
- }
- }
- public function login($username, $password) {
- global $PDO;
- $select = $PDO->prepare('SELECT username, id FROM servers WHERE (username=:username AND password=:password) LIMIT 1');
- $select->bindValue('username', $username);
- $select->bindValue('password', $password);
- $select->execute();
- if($select->rowCount() < 1) {
- $_SESSION['logged'] = "no-logged";
- } else {
- $data = $select->fetchObject();
- $uid = $data->id;
- $user = $data->username;
- $_SESSION['uid'] = $uid;
- $_SESSION['user'] = $user;
- $_SESSION['logged'] = "logged";
- header('Location: /index.php');
- }
- }
- public function dataUser($type) {
- global $PDO;
- if(!empty($this->userData->id) && !empty($this->userData->username)) {
- switch($type) {
- case 'id':
- return $this->userData->id;
- break;
- case 'user':
- return $this->userData->username;
- break;
- case 'firstname':
- return $this->userData->firstname;
- break;
- case 'lastname':
- return $this->userData->lastname;
- break;
- case 'email':
- return $this->userData->email;
- break;
- case 'pass':
- return $this->userData->password;
- break;
- case 'picture':
- return $this->userData->picture;
- break;
- }
- } else {
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement