Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2.  
  3. class User {
  4.  
  5. public $logged = false;
  6.  
  7. public function __construct(){
  8. global $db;
  9.  
  10. if(isset($_COOKIE['logged'])){
  11. $auth = explode(':', base64_decode($_COOKIE['logged']));
  12.  
  13. $sql = $db->prepare("SELECT * FROM users WHERE id = :id and password = :password LIMIT 1");
  14. $sql->execute(array(':id' => $auth[0], ':password' => $auth[1]));
  15. $check = $sql->fetchColumn();
  16. $user = $sql->fetch(PDO::FETCH_ASSOC);
  17.  
  18. var_dump($check);
  19. var_dump($user);
  20.  
  21. if ($check == true) {
  22. $this->logged = true;
  23. $this->id = $user['id'];
  24. $this->firstname = $user['firstname'];
  25. $this->secondname = $user['secondname'];
  26. }
  27. }
  28. }
  29.  
  30. # получаем ид
  31. public function getID(){
  32. return $this->id;
  33. }
  34.  
  35. # получаем имя и фамилию
  36. public function getFirstName(){
  37. return $this->firstname;
  38. }
  39.  
  40. public function getSecondName(){
  41. return $this->secondname;
  42. }
  43. }
  44.  
  45. $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement