<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require_once('./classes/User.php');
session_start();
//echo "<pre>";print_r($_GET);print_r($_POST);print_r($_SESSION);exit;
if(isset($_GET['code']) && $_GET['code']=='logout') {
session_destroy();
//unset($_SESSION['loggedin']);
session_unset();
setcookie('Loggedin', '', time()-3600, '/');
header("Location: ./login.php");
exit;
}
elseif( isset($_SESSION['loggedin']) && $_SESSION['loggedin'] ){
// die("long while ago");
header('Location: ./index.php');
exit;
}
elseif( isset($_POST['submit']) ){
// print_r($_POST);exit;
$_SESSION['loggedin'] = false;
$user = new User();
$error = '';
$user->username = $_POST['txtuser'];
$status = $user->login($_POST['txtpass'], $error);
// print_r($user);exit;
if( $status ){
$_SESSION['loggedin'] = true;
$_SESSION['full_name'] = $user->fullname;
setcookie('Loggedin', 'True', 0, '/');
// echo "<pre>";print_r($_GET);print_r($_POST);print_r($_SESSION);
// die("dead");
header('Location: ./index.php');
exit;
}
}
?>
<html>
<head>
<title>CSTracker Login Page</title>
<link rel="stylesheet" type="text/css" href="templates/css/css.css">
</head>
<body>
<?php if(isset($error)) echo $error; ?>
<form name="frmlogin" method="post" action="login.php">
<table cellspacing="5" cellpadding="1" width="250px">
<thead>
<tr>
<th colspan="2"><h2>Welcome to CSTracker</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td width="20px">Username</td>
<td width="30px"><input type="text" name="txtuser" id="user"/></td>
</tr>
<tr>
<td width="20">Password</td>
<td width="30"><input type="password" name="txtpass" id="txtpass"/></td>
</tr>
<tr>
<td width="20"><input type="submit" name="submit" value="Login"/></td>
<td width="30"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>