<?php
session_start();
$checkID = $_SESSION['company'];
	if($checkID == ""){			
		$checkID = $_SESSION['admin'];
	}
	else{};
	if($checkID == ""){
		$checkID = $_SESSION['agent'];
	}
	else{};
	if($checkID == ""){			
		echo"<script language=javascript>alert('Please login!!');window.location='http://www.wauhaha.com/smart/login.php'</script>";
	}
	else{};
///////////////////////////////////////////////////////////////////////////////////////
include("connect.php");
$ip=$_SERVER["REMOTE_ADDR"];
$nowdate = time(); // taking now logged in time
$nowdate2 = $nowdate + (20 * 60);

$tt = mysql_query("select * from logincontrol where id='$checkID'");
$ttt = mysql_fetch_array($tt);
$getcurrent1=$ttt['ipaddress'];
$getcurrent2=$ttt['endtime'];
$getcurrent3=$ttt['status'];

if ($getcurrent1 != $ip){
	echo "<script language='javascript'>alert ('Your account is login at other place! Please login again to continue.')</script>";
	session_destroy();
	session_unset();	
	echo"<script language=javascript>window.location='http://www.wauhaha.com/smart/login.php'</script>";
}
elseif ($nowdate > $getcurrent2){	
	mysql_query("Update logincontrol set status='0' where id='$checkID'");
    echo "<script language='javascript'>alert ('Your session has expired ! Please login again to continue.')</script>";
	echo "<script language='javascript'>window.location='http://www.wauhaha.com/smart/logout.php'</script>";
}
else{
	mysql_query("update logincontrol set ipaddress='$ip',starttime='$nowdate',endtime='$nowdate2',status='1' where id='$checkID'");
}
include("closeconnection.php");	
?>