<?php
	session_start();
	include("connect.php");
	
	$userID=$_POST["userID"];
	$pass=$_POST["pass"];
	
	isset($_SESSION['client']);
	
	$ip=$_SERVER['REMOTE_ADDR'];
	//$_SESSION['start'] = time();
	//$logindate = time();
	//$_SESSION['expire'] = $_SESSION['start'] + (20 * 60) ;
	//$logindate2 = $_SESSION['expire'];
	//$tt = mysql_query("select * from logincontrol where id='$userID'");
	//$ttt = mysql_fetch_array($tt);
	//$getcurrent1=$ttt['ipaddress'];
	//$getcurrent2=$ttt['starttime'];
	//$getcurrent3=$ttt['status'];
	
	//-------------------------Date & Time---------------------------//
	date_default_timezone_set ("Singapore"); 
		$ldate=date("d-m-Y", time());
		$ltime=date("h:i:sa", time());
		
	//-------Auto increment ID--------------//
	$str = "SELECT Max(recordID) FROM loginreport";
	
		$result2 = mysql_query ($str,$login);
		list($result2)=mysql_fetch_array($result2);
		$number = ++$result2;
			
		if($number == "1")
		{
			$number = "L000001";
		}
		
	$result=mysql_query("select * from customer where userID='$userID' and password='$pass'");
		if(mysql_num_rows($result) == 1 ){
				$_SESSION['client']= $userID;
				//mysql_query("update logincontrol set ipaddress='$ip',starttime='$logindate',endtime='$logindate2',status='1' where id='$userID'");
				mysql_query("INSERT INTO loginreport (recordID, user, ip, date, time)
				VALUES ('$number', '$userID','$ip','$ldate','$ltime')");
				echo"<script language=javascript>window.location='indexLogin.php'</script>";
		}else{
				echo "<script language=javascript>alert('failed login!!');window.location='loginPage.php?status=fail'</script>";
			}
?>