include('config.inc.php');
if(isset($usern))
$sql="select*from userin where logname='$usern' and pw='$passs' and online='0'";
$result=mssql_query($sql);
$num_rows=mssql_num_rows($result);
if($num_rows==1)
{
$sql="update userin set online='1' where '$usern'=logname";
$result=mssql_query($sql);
$sql1="UPDATE userin SET time_login= '".time()."' WHERE logname= '$usern'";
$result1=mssql_query($sql1);
}else{
setcookie("username_log",$user,time()-3600*24*356);
setcookie("password_log",$password_md5,time()-3600*24*356);
echo "<script>alert('Login ซ้อน');window.location = 'home.php';</script>";}
$sql2="UPDATE userin SET online='0' WHERE time_login <='".(time()-30)."'";
$result2=mssql_query($sql2);}
if(isset($user)){
$sql="select*from userin where logname='$user' and pw='$password_md5' and online='0'";
$result=mssql_query($sql);
$num_rows=mssql_num_rows($result);
if($num_rows==1)
{$sql="update userin set online='1' where '$user'=logname";
$result=mssql_query($sql);
$sql1="UPDATE userin SET time_login= '".time()."' WHERE logname= '$user'";
$result1=mssql_query($sql1);
}else{echo "<script>alert('Login ซ้อน');window.location = 'home.php';</script>";}
$sql2="UPDATE userin SET online='0' WHERE time_login <='".(time()-30)."'";
$result2=mssql_query($sql2);
}