¸ù¾Ýǰ̨Ìá½»µÄÇëÇ󣬵Ǽʱ£¬»ñÈ¡Óû§ÊäÈëµÄÓû§ÃûºÍÃÜÂ룬²¢ÓëÊý¾Ý¿âÖжÔÓ¦µÄÓû§ÃûºÍÃÜÂë½øÐбȶԣ¬Èç¹û±È¶Ô³É¹¦£¬Ôò½«ÐµĸüиÃÓû§µÇ¼ÐÅÏ¢£¬²¢×é×°jsonÊý¾Ý´«¸øǰ̨¡£
session_start(); require_once ('connect.php'); $action = $_GET['action']; if ($action == 'login') { //µÇ¼ $user = stripslashes(trim($_POST['user'])); $pass = stripslashes(trim($_POST['pass'])); if (empty ($user)) { echo 'Óû§Ãû²»ÄÜΪ¿Õ'; exit; } if (empty ($pass)) { echo 'ÃÜÂë²»ÄÜΪ¿Õ'; exit; } $md5pass = md5($pass); //ÃÜÂëʹÓÃmd5¼ÓÃÜ $query = mysql_query("select * from user where username='$user'"); $us = is_array($row = mysql_fetch_array($query)); $ps = $us ? $md5pass == $row['password'] : FALSE; if ($ps) { $counts = $row['login_counts'] + 1; $_SESSION['user'] = $row['username']; $_SESSION['login_time'] = $row['login_time']; $_SESSION['login_counts'] = $counts; $ip = get_client_ip(); //»ñÈ¡µÇ¼IP $logintime = mktime(); $rs = mysql_query("update user set login_time='$logintime',login_ip='$ip', login_counts='$counts'"); if ($rs) { $arr['success'] = 1; $arr['msg'] = 'µÇ¼³É¹¦£¡'; $arr['user'] = $_SESSION['user']; $arr['login_time'] = date('Y-m-d H:i:s',$_SESSION['login_time']); $arr['login_counts'] = $_SESSION['login_counts']; } else { $arr['success'] = 0; $arr['msg'] = 'µÇ¼ʧ°Ü'; } } else { $arr['success'] = 0; $arr['msg'] = 'Óû§Ãû»òÃÜÂë´íÎó£¡'; } echo json_encode($arr); //Êä³öjsonÊý¾Ý } elseif ($action == 'logout') { //Í˳ö unset($_SESSION); session_destroy(); echo '1'; }µ±Ç°Ì¨ÇëÇóÍ˳öʱ£¬Ö»Ðè×¢Ïúsession¾Í¿ÉÒÔ£¬²¢·µ»Ø1¸øǰ̨JS´¦Àí¡£×¢ÒâÉÏÊö´úÂëÖÐget_client_ip()ÊÇ»ñÈ¡¿Í»§¶ËIPµÄº¯Êý£¬ÏÞÓÚƪ·ùδÄÜÁгö£¬´ó¼Ò¿ÉÒÔÏÂÔØÔ´´úÂë²é¿´¡£
ºÃÁË£¬Ò»Ì×Íê³ÉµÄÓû§µÇ¼ºÍÍ˳ö³ÌÐòÍê³É£¬²»×ãÖ®´¦ÔÚËùÄÑÃ⣬»¶Ó´ó¼ÒÅúÆÀÖ¸Õý¡£
¡¡