Example #1
0
 function connect()
 {
     switch (UCTYPE) {
         case 'mysql':
             if (self::$conn = mysql_connect(UCSERVER . ':' . UCSERVER_PORT, UCUSER, UCPASSWD)) {
                 if (mysql_select_db(UCNAME, self::$conn)) {
                     mysql_query("SET character_set_connection=" . UCCHARSET . ", character_set_results=" . UCCHARSET . ", character_set_client=binary", self::$conn);
                 } else {
                     echo 'can not select db';
                     exit;
                 }
             } else {
                 echo 'can not connect db';
                 exit;
             }
             break;
         case 'mysqli':
             if (self::$conn = new mysqli(UCSERVER, UCUSER, UCPASSWD, UCNAME, UCSERVER_PORT)) {
                 self::$conn->query("SET character_set_connection=" . UCCHARSET . ", character_set_results=" . UCCHARSET . ", character_set_client=binary");
             } else {
                 echo 'can not connect db';
                 exit;
             }
             break;
     }
 }
Example #2
0
 function doLogin($acc = '', $pw = '')
 {
     $dbl = new DB();
     $json = new JSON();
     if (strtoupper(DBCHARSET) == 'GBK') {
         $acc = mb_convert_encoding($acc, 'GBK', 'UTF-8');
     }
     //查用户名
     if (UCDBON == 1) {
         $db = new DBUC();
         $sql = "SELECT uid,username,password,salt FROM `" . UC_PRE . "members` WHERE username = '******'";
         $pwcheck = $db->fetch_all($sql);
     } else {
         $sql = "SELECT uid,username,password,salt FROM `" . UC_PRE . "members` WHERE username = '******'";
         $pwcheck = $dbl->fetch_all($sql);
     }
     //判断是否是GBK编码的数据库
     if (strtoupper($dbcharset) == 'GBK') {
         if (!empty($pwcheck[0])) {
             foreach ($pwcheck[0] as $k => $v) {
                 $pwcheck[0][$k] = mb_convert_encoding($v, 'GBK', 'UTF-8');
             }
         }
     }
     if (!empty($pwcheck)) {
         if (md5($pw . $pwcheck[0]['salt']) == $pwcheck[0]['password']) {
             //查是否登陆过
             $sql = "SELECT sid FROM `" . DB_PRE . "common_session_app` WHERE uid = '" . $pwcheck[0]['uid'] . "'";
             $sescheck = $dbl->fetch_all($sql);
             if (empty($sescheck)) {
                 //设置sid
                 $sql = "INSERT INTO `" . DB_PRE . "common_session_app` (`sid`, `ip`, `uid`, `username`, `lastlogin`) VALUES ('" . md5($pwcheck[0]['password'] . time()) . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $pwcheck[0]['uid'] . "', '" . $pwcheck[0]['username'] . "', '" . time() . "');";
                 $sesset = $dbl->query($sql);
                 if ($sesset) {
                     $sid = md5($pwcheck[0]['password'] . time());
                 } else {
                     $sid = 500;
                 }
             } else {
                 //更新最近登陆时间
                 $sql = "UPDATE `" . DB_PRE . "common_session_app` SET `lastlogin` = '" . time() . "' WHERE `sid` = '" . $sescheck[0]['sid'] . "'";
                 $upsid = $dbl->query($sql);
                 if ($upsid) {
                     $sid = $sescheck[0]['sid'];
                 } else {
                     $sid = 500;
                 }
             }
         } else {
             $sid = 'aperror';
         }
     } else {
         $sid = 'aperror';
     }
     //输出json
     if (empty($sid)) {
         $code = '404';
         $data_array = array();
     } else {
         if (!empty($sid)) {
             $code = '200';
             $data_array[0] = array('sessionid' => $sid, 'uid' => $pwcheck[0]['uid'], 'groupid' => $pwcheck[0]['groupid']);
         } elseif ($sid == 500) {
             $code = '500';
             $data_array = array();
         }
     }
     $json_string = $json->ArrayGetjson($data_array, $code);
     echo $json_string;
 }