<?php
error_reporting(0);
ini_set("date.timezone","PRC");
isset($_POST['username'])?$username = $_POST['username'] :$username = null;
isset($_POST['userpass'])?$userpass = $_POST['userpass'] :$userpass = null;
if($username!=null and $userpass!=null){
    require_once("config.php");
    $sql = "select username,userpass,rand,shenfen from dunling_user where username='$username'";
    $ery = mysql_query($sql,$config);
    $num = mysql_num_rows($ery);
    if($num == "1"){
    $list = mysql_fetch_array($ery);
    $rand = $list['rand'];
    $mypass = $list['userpass'];
    $uspass = sha1($userpass.$rand);
    $shenfen = $list['shenfen'];
    if($mypass != $uspass){
        echo "userpass_error";
    }else{
        //LOGIN
    setcookie("user",$username,time()+3600*72,'/');
    setcookie("pass",$uspass,time()+3600*72,'/');
    $time = date("Y-m-d H:i:s");
    $upsql = "update dunling_user set logintime='$time' where username='$username'";
    mysql_query($upsql,$config);
    echo $shenfen;
    }
    
    
    }else{
        echo "username_error";
    }
    mysql_close();
}
?>