<?php
include_once("../config.php");

	$con=mysql_connect(constant('UC_DBHOST'),constant('UC_DBUSER'),constant('UC_DBPW'));
	mysql_select_db(constant('UC_DBNAME'),$con);
	mysql_query("set names 'gbk'");

if($_REQUEST[close]=='close'){

	if(empty($_REQUEST[myuid])){exit();}
	$myuid=$_REQUEST[myuid];
	$tablename="`".$_SC['dbname']."`.".$_SC['tablepre']."session";
	mysql_query("delete from ".$tablename." where uid=$myuid");//app退出时删除在线列表

}else{

	if(empty($_REQUEST[username])){exit();}
	if(empty($_REQUEST[password])){exit();}
	if(empty($_REQUEST[host])){exit();}
	$username = trim(iconv("UTF-8","gb2312",$_REQUEST[username]));
	$password = trim(iconv("UTF-8","gb2312",$_REQUEST[password]));
	$host = iconv("UTF-8","gb2312",$_REQUEST[host]);

    $con=mysql_connect(constant('UC_DBHOST'),constant('UC_DBUSER'),constant('UC_DBPW'));
    mysql_select_db(constant('UC_DBNAME'),$con);
	$tablename=constant('UC_DBTABLEPRE')."members";
	$result=mysql_query("select uid,password,salt from ".$tablename." where username='$username'");//登陆信息确认
	//echo "select uid,password,salt from ".$tablename." where username='$username'";
    $row=mysql_fetch_array($result);
    $results[] = "<options>";

		if($row[password]==md5(md5($password).$row[salt])){
			$uuid = $row[uid];
				$results[] = "<option><uuid>".$uuid."</uuid></option>";
				$username2 = iconv("gb2312","UTF-8",$username);
				$results[] = "<option><username>".$username2."</username></option>";
				$results[] = "<option><answer>OK</answer></option>";
				$tablename2="`".$_SC['dbname']."`.".$_SC['tablepre']."session";
				$time=time();
				$mmm=mysql_query("select uid from ".$tablename2." where uid=$uuid");//查找是否已经登录
				//echo "select uid from ".$tablename2." where uid=$uuid";
				$kkk=mysql_fetch_array($mmm);
					if(empty($kkk)){
						mysql_query("insert into ".$tablename2." (uid,username,host,lastactivity) value($uuid,'$username','$host',$time)");//更新在线列表
						//echo "insert into ".$tablename2." (uid,username,host,lastactivity) value($uuid,'$username','$host',$time)";
					}else{
						mysql_query("update ".$tablename2." set host='$host',lastactivity=$time where uid=$uuid");
						//echo "update ".$tablename2." set host='$host',lastactivity=$time where uid=$uuid";
    }

		}else{

			$results[] = "<option><answer>ERROR</answer></option>";
    }
    $results[] = "</options>";

    print implode("\n", $results);
	}
?>