Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Users.php
- ```php
- <?php
- class Users
- {
- // ATRIBUTES
- public $login; // string
- public $password; // string
- private $logged; // true/false
- private $activity; // true/false
- private $userArray = [ // пользователи бд (логин => пароль)
- 'Alex' => '1234',
- 'Tom' => '4321',
- 'Michael'=> '1243'
- ];
- // METHODS
- public function __construct($login, $password) {
- $this->login = $login;
- $this->password = $password;
- // defaults atributes
- $this->logged = false;
- $this->activity = false;
- }
- public function logIn() {
- $this->logged = true;
- }
- public function logOut() {
- $this->logged = false;
- }
- public function getLogged() {
- return $this->logged;
- }
- public function checkUserInArray() {
- if ( $this->userArray[$this->login] === $this->password ) {
- $this->activity = true;
- } else {
- $this->activity = false;
- }
- }
- public function getActivity() {
- return $this->activity;
- }
- }
- ?>
- ```
- index.php
- ```php
- <?php
- ini_set('display_errors', 1);
- include 'Users.php';
- $user = new Users('Alex', '1234');
- $user->logIn();
- echo "Пользователь авторизован ? ";
- var_dump($user->getLogged());
- echo "<br>";
- $user->checkUserInArray();
- echo "Пользователь принадлежит массиву ? ";
- var_dump($user->getActivity());
- echo "<br>";
- ?>
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement