<?php
/*********************/
/*                   */
/*  DeZend For PHP5  */
/*  BY WwW.DeZend.CC */
/*   With Bendy [2]  */
/*                   */
/*********************/

require( "_inc.php" );
$userName = trim( $_POST['userName'] );
$userPwd = trim( $_POST['userPwd'] );
$remember = !empty( $_POST['remember'] ) ? 1 : 0;
if ( empty( $userName ) || empty( $userPwd ) )
{
	exit( "登录失败<br>请输入用户名和密码。" );
}
$sql = "SELECT f_id, f_pwd, f_status FROM ".$gDb['prefix'].( "users WHERE (f_userName='".$userName."')" );
$arrUserInfo = $db->fetchrow( $sql );
if ( empty( $arrUserInfo['f_id'] ) )
{
	exit( "登录失败<br>用户不存在，或是密码错误。" );
}
if ( $userPwd != $arrUserInfo['f_pwd'] && md5( $userPwd ) != $arrUserInfo['f_pwd'] )
{
	exit( "登录失败<br>用户不存在，或是密码错误。" );
}
$uId = $arrUserInfo['f_id'];
$loginTime = time( );
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "UPDATE ".$gDb['prefix'].( "users SET f_lastTime='".$loginTime."', f_lastIp='{$ip}', f_loginTimes=f_loginTimes+1 WHERE ((f_id='{$uId}') AND (f_userName='{$userName}'))" );
$db->query( $sql );
$GLOBALS['_SESSION']['ses_userId'] = $uId;
$GLOBALS['_SESSION']['ses_userName'] = $userName;
$redirectUrl = "../user/";
if ( !empty( $_SESSION['ses_redirectUrl'] ) )
{
	$redirectUrl = base64_decode( $_SESSION['ses_redirectUrl'] );
	unset( $_SESSION['ses_redirectUrl'] );
}
header( "location: ".$redirectUrl );
?>
