Created
December 19, 2016 10:35
-
-
Save kaqfa/168575dace4eb788be519aeb28b02782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
require "../pdo/connection.php"; | |
function loginCheck(){ | |
global $db; | |
$prep = $db->prepare("select * from users where username=?"); | |
$prep->execute(array($_POST['username'])); | |
$res = $prep->fetch(); | |
if($res['password'] == md5($_POST['password'])) | |
return $res; | |
else | |
return false; | |
} | |
$login = loginCheck(); | |
if($_REQUEST['action']=='logout'){ | |
session_destroy(); | |
unset($_COOKIE['login']); // acceptable | |
setcookie('login', null, -1); // better | |
header("location:login.php"); | |
} else if($login){ | |
// User found and will be redirected to admin page | |
$_SESSION['admin'] = $login; | |
setcookie('login', $login['username']); | |
header("location:admin.php"); | |
} else { | |
// User not found and will be redirected to login page again | |
header("location:login.php"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment