<?php
require_once('session.php');
require_once('global4app.php');
$login_query = 'select md5(\''.$_POST['passwd'].'\') as userpasswd, user_id, user_password, user_username from users where user_username =\''.$_POST['username'].'\'';
//echo $login_query;
$users = db_loadList($login_query);
$error_msg = "Not a valid User, Please try again...";
if (count($users) <=0)
{
header( 'Location: index.php?error=' . $error_msg ) ;
}
else
foreach($users as $row)
{
if ($row["userpasswd"] == $row["user_password"])
{
//success , set sessions and redirect
$_SESSION["uid"] = $row['user_id'];
$_SESSION["username"] = $_POST["username"];
if ($_SESSION["username"] == "admin")
{
$_SESSION["admin"] = "true";
}
else
{
$_SESSION["admin"] = "false";
}
header('Location: startPage.php' );
}
else
{
$error_msg = "Incorrect Password, Please try again...";
header('Location: index.php?error=' . $error_msg );
}
}
?>