Example #1
0
<?php

//namespace App\Admin;
use App\DB;
use App\Session;
require "../../config.php";
require_once "../../vendor/autoload.php";
$conn = DB::GetConnection();
if (isset($_POST['btnLogin']) && isset($_POST['txtEmail']) && isset($_POST['txtPass'])) {
    $username = $_POST['txtEmail'];
    $pass = $_POST['txtPass'];
    if (empty($username) || empty($pass)) {
        header("Location: " . APP_DIR . "public/index.php");
    }
    if (!filter_var($username, FILTER_VALIDATE_EMAIL)) {
        header("Location: " . APP_DIR . "public/index.php");
    }
    $stmt = $conn->prepare("select user_id,user_name from users where user_email= ? and user_pass= password( ? ) ");
    $stmt->bindParam(1, $username, \PDO::PARAM_STR);
    $stmt->bindParam(2, $pass, \PDO::PARAM_STR);
    $stmt->execute();
    if ($row = $stmt->fetchObject()) {
        var_dump($row);
        Session::SetKey('user_id', $row->user_id);
        Session::SetKey('user_name', $row->user_name);
        header("Location: admin.php");
    } else {
        die("Niste Admin");
    }
}