Ejemplo n.º 1
0
            return false;
        }
    }
    public function getLogin()
    {
        if ($this->isAuth()) {
            return $_SESSION["login"];
        }
    }
    public function out()
    {
        $_SESSION = array();
        session_destroy();
    }
}
$auth = new AuthClass();
if (isset($_POST["login"]) && isset($_POST["password"])) {
    if (!$auth->auth($_POST["login"], $_POST["password"])) {
        echo "Логи/пароль введены неверно";
        echo $data["user_password"];
    }
}
if (isset($_GET["is_exit"])) {
    if ($_GET["is_exit"] == 1) {
        $auth->out();
        header("Location: ?is_exit=0");
    }
}
if ($auth->isAuth()) {
    echo "Hello" . $auth->getLogin();
    echo "</br><a href='?is_exit=1'>Exit</a>";
Ejemplo n.º 2
0
    {
        if ($this->isAuth()) {
            //Если пользователь авторизован
            return $_SESSION["login"];
            //Возвращаем логин, который записан в сессию
        }
    }
    public function out()
    {
        $_SESSION = array();
        //Очищаем сессию
        session_destroy();
        //Уничтожаем
    }
}
$auth = new AuthClass();
if (isset($_POST["login"]) && isset($_POST["password"])) {
    //Если логин и пароль были отправлены
    if (!$auth->auth($_POST["login"], $_POST["password"])) {
        //Если логин и пароль введен не правильно
        echo "<h2 style=\"color:red;\">Логин и пароль введен не правильно!</h2>";
    }
}
if (isset($_GET["is_exit"])) {
    //Если нажата кнопка выхода
    if ($_GET["is_exit"] == 1) {
        $auth->out();
        //Выходим
        header("Location: ?is_exit=0");
        //Редирект после выхода
    }