<?php

session_start();
require_once './controller/UserCtrl.php';
$uid = isset($_POST['username']) ? $_POST['username'] : '';
$pwd = isset($_POST['password']) ? $_POST['password'] : '';
if (UserCtrl::getType($_COOKIE['uid']) != 1903) {
    echo '<script>window.location.href="index.php";</script>';
}
if ($uid != '' && $pwd != '') {
    if (UserCtrl::login(new User($uid, $pwd)) && UserCtrl::getType($uid) == 1903) {
        $_SESSION['admin'] = '^f8fg3j5&(:c3';
        echo '<script>window.location.href="admin.php";</script>';
    } else {
        if (UserCtrl::login(new User($uid, $pwd)) && UserCtrl::getType($uid) != 1903) {
            setcookie('uid', $uid);
            echo '<script>alert("You dont have admin access. Redirect to homepage");</script>';
            echo '<script>window.location.href="index.php";</script>';
        } else {
            echo '<script>alert("Incorrect username/password.");</script>';
        }
    }
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
Beispiel #2
0
        unset($_COOKIE['uid']);
        unset($_SESSION['admin']);
        setcookie("uid", "", time() - 3600);
        echo '<script>window.location.href = "login.php";</script>';
        $b = false;
    }
}
if (isset($_COOKIE['uid']) && $_COOKIE['uid'] != '') {
    echo '<script>window.location.href = "index.php";</script>';
    $b = false;
}
if (isset($_POST['u']) && isset($_POST['p'])) {
    $b = false;
    $u = $_POST['u'];
    $p = $_POST['p'];
    if (UserCtrl::login(new User($u, $p))) {
        echo 'okkkk';
    } else {
        echo 'naaah';
    }
}
?>

<?php 
if ($b) {
    ?>
<!DOCTYPE html>
<html class="login">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">