www.gusucode.com > 仿51.com的php源码 1.1 > login.php

    <?php

/*
 * 文 件 名:login.php
 * 功    能:
 * 说    明:
 * 函数说明:
 *
*/
session_start();
//session_cache_limiter('private, must-revalidate');

require_once("include/global.php");
require_once("include/dbclass.php");
require_once("share.php");
$db=new DbConn();
//得IP开始
   if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
				   $ip = getenv("HTTP_CLIENT_IP");
			   else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
				   $ip = getenv("HTTP_X_FORWARDED_FOR");
			   else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
				   $ip = getenv("REMOTE_ADDR");
			   else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
				   $ip = $_SERVER['REMOTE_ADDR'];
			   else
				   $ip = "unknown";


//得IP结束

//$P = filter($_POST);
//$G = filter($_GET);

$username=$_POST['passport_51_user'];
$password=$_POST['passport_51_password'];

$refer=$_POST["login_refer"];

if($_GET['action'] == "login"){
	$sql="select id,User_Account,User_Password,User_Sex,nickname,User_Shen,User_Shi,dengji,huiyuan,RegTime,face,ThistLoginTime  from userdata where User_Account='$username'";
	$query_id=$db->query($sql);
$num=$db->num_rows($query_id);
	
	if($num== 0){	
	echo ("<script>alert('用户名不存在');history.back();</script>");
	exit();
	}
	$row = $db->getRs($sql);
	if($password == $row['User_Password']){
			
		setcookie("uid", $row['User_Account']);
		setcookie("nickname", $row['nickname']);
		setcookie("vip",$row['huiyuan']);
		setcookie("shen",$row['User_Shen']);
		setcookie("city",$row['User_Shi']);
		
		//生成JS文件
		$b="1e";
		$bb=$b."/".$row['User_Account'];
		
		//if(!is_dir("1e"))
		//{
		//mkdir("1e",0777);
		//}
		if(!is_dir($b))
		{
		//如果目前不存在
		 @mkdir($b,0777);
		}
		if(!is_dir($bb))
		{
		@mkdir($bb,0777);
		}
		$u_b="User/upfile/".$row['User_Account'];
		if(!is_dir($u_b))
		{
		//如果目前不存在
		 @mkdir($u_b,0777);
		}
		//得到JS模板
		$fp = @fopen ("temp_js.html","r"); 
$content = fread ($fp,filesize ("temp_js.html"));

$content= str_replace ("{user}",$row['User_Account'],$content);
$content= str_replace ("{vip}",$row['huiyuan'],$content);
$content= str_replace ("{sex}",$row['User_Sex'],$content);
$content= str_replace ("{photo}","/User/".$row['face'],$content); 
$content= str_replace ("{niname}",$row['nickname'],$content); //echo $content;
$content=str_replace ("{confirm}",$row['videorz'],$content); 

$filename=$bb."/".$row['User_Account'].".js"; 
$handle = fopen ($filename,"w"); //打开文件指针,创建文件 

if (!is_writable ($filename))
{
echo "<script>alert('文件:不可写,请检查其属性后重试!');history.back();</script>"; 
exit();
 }
if (!fwrite ($handle,$content))
{ 
echo "<script>alert('生成文件失败!');history.back();</script>";
exit();
}
fclose ($handle); //关闭指针 


		
		
		//查看是不是当天登陆的
		//$sql="select AboutTime from mysyslog  where User_Account='$username' order by AboutTime desc limit 0,1";	
		//$query_sql=$db->query($sql);		
		//$timerow=mysql_fetch_array($query_sql);
		// $timerow=$db->getRs($sql);
		//echo $timerow["AboutTime"];
		//exit();
		//是不是以前没有记录的,如果没有就先加一条,如果有了,就查看是不是当天已有登陆
		
		//得到IP
		/*
		echo $ip;
		echo "<br>";
		exit();
		*/
		$T=date('Y-m-d H:i:s',time());

		
		if ($row['ThistLoginTime']==null)
		{
		
		$txt= date('Y-m-d',time())."登陆, 赠送 5 点积分!(原来积分 ".$row['dengji'].", 现在积分". ((int)$row['dengji']+5).")";
		$sql="insert into mysyslog (User_Account,EventTxt,Who_Account,AboutTime) values ('$username','$txt','$username','$T')";
		$db->Execute($sql);	
		
				//更新登陆时的信息开始
			$sql="update userdata set dengji=dengji+5,LoginTimes=LoginTimes+1,LastLoginIp
=ThistLoginIp,ThistLoginIp='$ip',LastLoginTime=ThistLoginTime,ThistLoginTime='$T' where User_Account='$username'";
		$db->Execute($sql);
		//更新登陆时的信息结束	
		}
		else
		{
		$tomorrow  = mktime(0,0,0,date("m") ,date("d"),date("Y"));
$tomorrow1  = mktime(0,0,0,date("m",strtotime($row['ThistLoginTime'])),date("d",strtotime($row['ThistLoginTime'])),date("Y",strtotime($row['ThistLoginTime'])));
		//得到两个时间差
		
		if($tomorrow-$tomorrow1>=86400)
		{
		//$sql="update userdata set dengji=dengji+5 where User_Account='$username'";
		
		$txt= date('Y-m-d',time())."登陆, 赠送 5 点积分!(原来积分 ".$row['dengji'].", 现在积分". ((int)$row['dengji']+5).")";
		$sql="insert into mysyslog (User_Account,EventTxt,Who_Account,AboutTime) values ('$username','$txt','$username','$T')";
		$db->Execute($sql);	
				//更新登陆时的信息开始
			$sql="update userdata set dengji=dengji+5,LoginTimes=LoginTimes+1,LastLoginIp
=ThistLoginIp,ThistLoginIp='$ip',LastLoginTime=ThistLoginTime,ThistLoginTime='$T' where User_Account='$username'";
		$db->Execute($sql);
		//更新登陆时的信息结束
		}		
				
		}			
		/*
		$_SESSION['uid'] = $row['mid'];
		$_SESSION['una'] = $username;
		$_SESSION['uju'] = $row['jur'];
		$_SESSION['urn'] = $row['realname'];
		*/
		//$db->query("UPDATE `advunion`.template_memebers SET uptime = '".time()."' WHERE mid = '".$row['mid']."'");
		//echo "登陆成功!3秒内转入操作页面!^_^";
		//先看看没有填写好资料
		if($row['nickname']==null)
		{
		header("Location:User/MainInfo.php");
		}
		else
		{
		if($refer=="")
		{
		header("Location:User/Main.php");
		}
		else
		{
		header("Location:$refer");
		}
		}
		//判断在线情况
		if($_POST["passport_51_ishidden"]!="1")
		{
		//如果已在线了,那就不用增加了,如果不在,那就加
		$sqlon_line="select id from on_line where User_Account='$username'";
		$rowno_line = $db->getRs($sqlon_line);
		if($rowno_line==null)
		{
		$sqlin="insert into on_line (User_Account,on_time) values ('$username','$T')";
		$db->Execute($sqlin);		
		}				
		}
	}
	else
	{ 
	echo "<script>alert('密码错误');history.back();</script>";
	}
}
else if($_GET['action'] == "logout"){
	$uid = $_COOKIE['uid'];
	$nickname=$_COOKIE["nickname"];
	//删除在线列表
	$sql="delete from on_line where User_Account='$uid'";	
	$db->Execute($sql);
	setcookie("uid","",time() - 3600);
	setcookie("nickname","",time() - 3600);
	setcookie("vip","",time() - 3600);
	setcookie("shen","",time() - 3600);
	setcookie("city","",time() - 3600);
    //setcookie("una","",time() - 3600);
	//setcookie("uju","",time() - 3600);
	//setcookie("urn","",time() - 3600);
	//setcookie("utp","",time() - 3600);
	
	//echo "登出成功";
	
	$referer=$_SERVER["HTTP_REFERER"];
	//echo $referer;
	//exit();
	header("Location:$referer");
	
	//<script>alert('登出成功');window.location.href='index.php';
	//ErrorMsg("登出成功",2,'index.html',$uid);
}
?>