File: //home/bk/efi/eficenter.ru/consultant/admin.php
<?php
header("Content-type: text/html; charset=UTF-8"); session_start(); error_reporting(0); class Admin{ public $_admin = false; public $admin_login; public $admin_password; public function __construct(){ $this->login(); if($this->_admin){ if(isset($_GET['logout'])){ $this->loguot(); } $this->viewPanel(); }else{ if($_SERVER['REQUEST_METHOD'] == 'POST'){ if(!empty($_POST['admin_login']) AND !empty($_POST['admin_password'])){ $this->admin_login = $this->filter($_POST['admin_login']); $this->admin_password = $this->filter($_POST['admin_password']); $this->checkLogin(); }else{ $this->messages("Заполните все поля"); } }else{ header('Location: index.php'); exit; } } } public function login(){ if(isset($_SESSION['who']) AND $_SESSION['who'] == "admin") $this->_admin = true; } public function filter($data){ return trim($data); } public function checkLogin() { $path = 'config/admin_config.php'; if (file_exists($path)){ require $path; if($this->admin_login != ADMIN_LOGIN OR $this->admin_password != ADMIN_PASSWORD){ $this->messages("Не правильный логин или пароль!"); }else{ $this->setSession(); } } else { die('Файл '.$path.' не найден!'); } } public function setSession(){ $_SESSION['who'] = "admin"; $this->_admin = true; $this->viewPanel(); } public function viewPanel(){ if(!empty($_SESSION['messages'])){ $mess_admin = $_SESSION['messages']; unset($_SESSION['messages']); } require_once 'view/admin_panel.php'; } public function messages($text){ $message = $text; require_once 'view/login_form.php'; } public function loguot(){ session_destroy(); header('Location: index.php'); exit; } } $admin = new Admin(); ?>