访问页面的用户身份验证

时间:2015-01-11 17:21:27

标签: php authentication

我正在进行页面身份验证。它可以登录,但如果有人试图通过URL访问页面,我希望它能使其他页面上的用户身份验证膨胀。如果此人不是登录用户,则将该人重定向到登录页面。我通过使用会话来尝试它,但它不起作用。我跟随MVC结构

我是这样做的

我的loginController

    <?php
//LoginController
if($_POST)
{
    if(isset($_POST['submit']) AND $_POST['submit'] == "login")
    {
        $username = $_POST['username'];
        $password = $_POST['password'];
        try
        {
            include '../model/Login.php';
            $login = new Login($db, $username, $password);

            if($login == TRUE)
            {
                session_start();
                $_SESSION['username'] = $username;
                header("Location:../index.php");
            }

        }
        catch (Exception $exc)
        {
            echo $exc->getMessage();
        }

    }
}

我的索引控制器(主页)

<?php
include 'model/Database.php';
session_start();
//Checks if the user is logged in.
if(!isset($_SESSION['username'])) {
//echo"<h2>You have no access to this page!";
    include 'view/login.php';
    die();
}
include 'c:/wamp/www/mvc/model/Display.php';

$displayPatients = new Display($db);
$dataDisplay = $displayPatients->getData();
include 'view/Main.php';
?>

0 个答案:

没有答案
相关问题