<?php
session_start();
include_once('connect.php');
if(isset($_SESSION['username'])){
header('location:controlpanel.html');
}
if($_SERVER['REQUEST_METHOD']=='POST'){
$u = mysqli_real_escape_string($con, $_POST['user']);
$p = mysqli_real_escape_string($con, $_POST['pass']);

$query = mysqli_query($con, "SELECT id FROM admin WHERE username= '$u' AND password ='$p' ");
if(mysqli_num_rows($query)>0){
$_SESSION['user'] = $user;
$_SESSION['start'] = time(); // Taking now logged in time.
            // Ending a session in 30 minutes from the starting time.
            $_SESSION['expire'] = $_SESSION['start'] + (30 * 60);
header("location:./controlpanel.html");
}else{
echo "<script type='text/javascript'>
		alert('failed');
		window.location='admin_login.htm';
		</script>";
}	
}
?>