Skip to content

Instantly share code, notes, and snippets.

@deuterium7
Last active August 2, 2017 19:34
Show Gist options
  • Save deuterium7/49dd7d2c62dac07cfa5915aff202740b to your computer and use it in GitHub Desktop.
Save deuterium7/49dd7d2c62dac07cfa5915aff202740b to your computer and use it in GitHub Desktop.
Zabornyi Alex

Users.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
	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>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment