Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php include '../classes/Adminlogin.php'; ?>
- <?php
- $al = new Adminlogin();
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $adminUser = $_POST['adminUser'];
- $adminPass = md5($_POST['adminPass']);
- $loginChk = $al->adminLogin($adminUser,$adminPass);
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <!-- Meta, title, CSS, favicons, etc. -->
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Admin Login</title>
- <!-- Bootstrap -->
- <link href="vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
- <!-- Font Awesome -->
- <link href="vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
- <!-- NProgress -->
- <link href="vendors/nprogress/nprogress.css" rel="stylesheet">
- <!-- Animate.css -->
- <link href="../vendors/animate.css/animate.min.css" rel="stylesheet">
- <!-- Custom Theme Style -->
- <link href="build/css/custom.min.css" rel="stylesheet">
- </head>
- <body class="login">
- <div>
- <a class="hiddenanchor" id="signup"></a>
- <a class="hiddenanchor" id="signin"></a>
- <div class="login_wrapper">
- <div class="animate form login_form">
- <section class="login_content">
- <form action="" method="post">
- <h1>Help Educare Login</h1>
- <!--Show Message-->
- <span style="color: red; font-size: 18px;">
- <?php
- if (isset($loginChk)) {
- echo $loginChk;
- }
- ?>
- </span>
- <!--Show Message End-->
- <div>
- <input type="text" class="form-control" placeholder="Username" name="adminUser" />
- </div>
- <div>
- <input type="password" class="form-control" placeholder="Password" name="adminPass" />
- </div>
- <div>
- <input class="btn btn-default submit" type="submit" value="Login" />
- </div>
- <div class="clearfix"></div>
- <div class="separator">
- <!-- <p class="change_link">New to site?
- <a href="#signup" class="to_register"> Create Account </a>
- </p>
- <div class="clearfix"></div>
- <br /> -->
- <div>
- <h1><i class="fa fa-paw"></i> Help Educare</h1>
- <p>©2018 All Rights Reserved Help Educare.</p>
- </div>
- </div>
- </form>
- </section>
- </div>
- </div>
- </div>
- </body>
- </html>
- <?php
- $filepath = realpath(dirname(__FILE__));
- include ($filepath.'/../lib/Session.php');
- Session::checkLogin();
- include_once ($filepath.'/../lib/Database.php');
- include_once ($filepath.'/../helpers/Format.php');
- ?>
- <?php
- /**
- * Adminlogin Class
- */
- class Adminlogin {
- private $db;
- private $fm;
- public function __construct(){
- $this->db = new Database();
- $this->fm = new Format();
- }
- public function adminLogin($adminUser,$adminPass){
- $adminUser = $this->fm->validation($adminUser);
- $adminPass = $this->fm->validation($adminPass);
- $adminUser = mysqli_real_escape_string($this->db->link, $adminUser);
- $adminPass = mysqli_real_escape_string($this->db->link, $adminPass);
- if (empty($adminUser) || empty($adminPass)) {
- $loginmsg = "Username and Password must not be empty!!";
- return $loginmsg;
- } else{
- $query = "SELECT * FROM tbl_admin WHERE adminUser = '$adminUser' AND adminPass = '$adminPass'";
- $result = $this->db->select($query);
- if ($result != false) {
- $value = $result->fetch_assoc();
- Session::set("adminlogin", true);
- Session::set("adminId", $value['adminId']);
- Session::set("adminUser", $value['adminUser']);
- Session::set("adminName", $value['adminName']);
- Session::set("role", $value['role']);
- header("Location:dashboard.php");
- } else{
- $loginmsg = "Username and Password not match !!";
- return $loginmsg;
- }
- }
- }
- }
- <?php
- /**
- * Session Class
- **/
- class Session{
- public static function init(){
- if (version_compare(phpversion(), '5.4.0', '<')) {
- if (session_id() == '') {
- session_start();
- }
- } else {
- if (session_status() == PHP_SESSION_NONE) {
- session_start();
- }
- }
- }
- public static function set($key, $val){
- $_SESSION[$key] = $val;
- }
- public static function get($key){
- if (isset($_SESSION[$key])) {
- return $_SESSION[$key];
- } else {
- return false;
- }
- }
- public static function checkSession(){
- self::init();
- if (self::get("adminlogin") == false) {
- self::destroy();
- header("Location:login.php");
- }
- }
- public static function checkLogin(){
- self::init();
- if (self::get("adminlogin")== true) {
- header("Location:dashboard.php");
- }
- }
- public static function destroy(){
- session_destroy();
- header("Location:login.php");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement