<?php
//controllers/login.php

function login($kw){
    require_once __DIR__.'/../setting.php';
    require_once __DIR__.'/admin/users/table.php';

    table($kw);

    $kw->mset([
        'appName'=>$setting['siteTitle'], 
        'title'=>'ទំព័រ​ចុះ​ឈ្មោះ', 
        'date'=>$setting['date'],
        'message'=>$setting['message']
    ]);

    $view=new View;
    echo $view->render('views/login.php');
}

 

<?php
//controllers/login_post.php

function checkUser($kw){
    require_once 'setting.php';

    $kw->mset([
        'appName'=>$setting['siteTitle'], 
        'title'=>'ទំព័រ​គ្រប់គ្រង', 
        'date'=>$setting['date'],
        'message'=>$setting['message']
    ]);

    if($_SESSION){
        $view=new View;
        echo $view->render('views/admin/index.php');
    }else{
        $sql = 'SELECT * FROM users WHERE email="'.$kw->get('POST.email').'"';
        $email = $kw->get('DB')->exec($sql);
        if($email){
            $sql = 'SELECT * FROM users WHERE password="'.$kw->get('POST.password').'"';
            $password = $kw->get('DB')->exec($sql);
            if($password){
                $_SESSION["password"] = $user[0]['password'];
                $_SESSION["email"] = $user[0]['email'];

                $view=new View;
                echo $view->render('views/admin/index.php');
            }else{
                $kw->set('message', 'ពាក្យ​សំងាត់​មិនត្រឹមត្រូវ​ទេ');
                $view=new View;
                echo $view->render('views/login.php');
            }
        }else{
            $kw->set('message', 'Email ​មិនត្រឹមត្រូវ​ទេ');
            $view=new View;
            echo $view->render('views/login.php');
        }
    }
}

 

Epizy: http://khmerweb.epizy.com