PHP Classes

File: example/index.php

Recommend this page to a friend!
  Classes of Andrey Gadyukov   Tiny Auth   example/index.php   Download  
File: example/index.php
Role: Example script
Content type: text/plain
Description: Example script file
Class: Tiny Auth
Authenticate users with records stored in MySQL
Author: By
Last change:
Date: 12 years ago
Size: 1,412 bytes
 

Contents

Class file image Download
<?php
error_reporting
(E_ALL);
require_once
'../TinyAuth.php';
session_start();
?>
<!DOCTYPE html>
<head>
    <meta charset="utf-8" />
    <title> TinyAuth Example </title>
    <!-- Included CSS File -->
    <link rel="stylesheet" href="main.css">
</head>
<body>
    <div>
        <?php
       
if(TinyAuth::i()->getAuthStatus() == false){?>
<div class="block">
            <form method="POST" action="">
                <label>Login</label>
                <input required type="text" name="login">
                <div>
                    <label>Password</label>
                    <input required type="text" name="pass">
                </div>
                <button name="smbBt" type="submit">
                    Login
                </button>
            </form>
        </div>
        <?} else { ?>
<div class="success block">
            <div>
                Login success!
            </div>
            <div>
                Your name: <?=TinyAuth::i() -> getName() ?>
</div>
            <div>
                Your role: <?= TinyAuth::i() -> getRole()['name'] ?>
</div>
            <form method="POST">
            <button name="logout" type="submit">
                    Logout
                </button>
            </form>
        </div>
    </div>
    <?}
        if (isset(
$_POST['smbBt'])){
            if(
TinyAuth::i()->login($_POST['login'], $_POST['pass']) == false){?>
                <div class="block error">
                <div>
                    Login error! Check login or password and try again.
                </div>
                </div>
            <?} else {
               
header('Location: '.$_SERVER['PHP_SELF']);
            }
        }
        if (isset(
$_POST['logout'])){
           
TinyAuth::i()->logout();
           
header('Location: '.$_SERVER['PHP_SELF']);
        }
   
?>
</div>
</body>
</html>