Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. Users.php
  2. ```php
  3. <?php
  4. class Users
  5. {
  6. // ATRIBUTES
  7. public $login; // string
  8. public $password; // string
  9. private $logged; // true/false
  10. private $activity; // true/false
  11. private $userArray = [ // пользователи бд (логин => пароль)
  12. 'Alex' => '1234',
  13. 'Tom' => '4321',
  14. 'Michael'=> '1243'
  15. ];
  16.  
  17. // METHODS
  18. public function __construct($login, $password) {
  19. $this->login = $login;
  20. $this->password = $password;
  21.  
  22. // defaults atributes
  23. $this->logged = false;
  24. $this->activity = false;
  25. }
  26.  
  27. public function logIn() {
  28. $this->logged = true;
  29. }
  30.  
  31. public function logOut() {
  32. $this->logged = false;
  33. }
  34.  
  35. public function getLogged() {
  36. return $this->logged;
  37. }
  38.  
  39. public function checkUserInArray() {
  40.  
  41. if ( $this->userArray[$this->login] === $this->password ) {
  42. $this->activity = true;
  43. } else {
  44. $this->activity = false;
  45. }
  46. }
  47.  
  48. public function getActivity() {
  49. return $this->activity;
  50. }
  51. }
  52. ?>
  53. ```
  54. index.php
  55. ```php
  56. <?php
  57. ini_set('display_errors', 1);
  58.  
  59. include 'Users.php';
  60.  
  61. $user = new Users('Alex', '1234');
  62.  
  63. $user->logIn();
  64. echo "Пользователь авторизован ? ";
  65. var_dump($user->getLogged());
  66. echo "<br>";
  67.  
  68. $user->checkUserInArray();
  69. echo "Пользователь принадлежит массиву ? ";
  70. var_dump($user->getActivity());
  71. echo "<br>";
  72. ?>
  73. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement