Skip to content

Instantly share code, notes, and snippets.

@kaqfa
Created December 19, 2016 10:35
Show Gist options
  • Save kaqfa/168575dace4eb788be519aeb28b02782 to your computer and use it in GitHub Desktop.
Save kaqfa/168575dace4eb788be519aeb28b02782 to your computer and use it in GitHub Desktop.
<?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