<?php /** * Created by PhpStorm. * User: liguangming * Date: 15/11/30 * Time: 下午7:38 */ include 'string_illegal.php'; $string_illegal = new StringIllegal(); error_reporting(0); function PostParam($param) { return $_POST[$param] ? $_POST[$param] : ''; } $token = @PostParam('token'); error_log("token " . $token . " get level.\n", 3, "/var/tmp/api.log"); // Illegal value parameter 10017 if (!$string_illegal->isStrLength($token, 31, 33)) { $output = array('data' => NULL, 'info' => 'Illegal value parameter.', 'code' => 10017); exit(json_encode($output)); } // get user info from memcache $mem = new Memcache(); $mem->connect('127.0.0.1', 11211); $user_info = $mem->get($token); //error_log("user info is: \n" . json_encode($user_info) . "\n", 3, "/var/tmp/api.log"); // Token expired 20022 if (!$user_info) { error_log("Token " . $token . " expired.\n", 3, "/var/tmp/api.log"); $output = array('data' => NULL, 'info' => 'Token expired.', 'code' => 20022);
/** * Created by PhpStorm. * User: liguangming * Date: 15/11/21 * Time: 下午10:42 */ include 'string_illegal.php'; $string_illegal = new StringIllegal(); error_reporting(0); function PostParam($param) { return $_POST[$param] ? $_POST[$param] : ''; } $username = @PostParam('username'); $password = @PostParam('password'); error_log("Login by " . $username . "\n", 3, "/var/tmp/api.log"); // login mysql $con = mysqli_connect('127.0.0.1', 'root', '', 'api_db', '3306'); // Server error fail 50000 if (!$con) { $output = array('data' => NULL, 'info' => 'Server sql error.', 'code' => 50000); exit(json_encode($output)); } // new memcache object $mem = new Memcache(); $mem->connect('127.0.0.1', 11211); $output = array(); // Username, password cannot be empty 20002 if (!$username || !$password) { $output = array('data' => NULL, 'info' => 'Username and password cannot be empty.', 'code' => 20002);
/** * Created by PhpStorm. * User: liguangming * Date: 15/12/2 * Time: 上午9:38 */ include 'string_illegal.php'; $string_illegal = new StringIllegal(); error_reporting(0); function PostParam($param) { return $_POST[$param] ? $_POST[$param] : ''; } $username = @PostParam('username'); $password = @PostParam('password'); $nickname = @PostParam('nickname'); $output = array(); // Username, password and nickname cannot be empty 20002 if (!$username || !$password || !$nickname) { $output = array('data' => NULL, 'info' => 'Username, password and nickname cannot be empty.', 'code' => 20002); exit(json_encode($output)); } // Illegal value parameter 10017 if (!$string_illegal->userName($username, 'ALL', 20) || !$string_illegal->isEngLength($username, 6, 20) || !$string_illegal->passWord(6, 20, $password) || !$string_illegal->isEnglish($password) || !$string_illegal->isStrLength($nickname, 2, 12)) { $output = array('data' => NULL, 'info' => 'Illegal value parameter.', 'code' => 10017); exit(json_encode($output)); } // insert mysql $con = mysqli_connect('127.0.0.1', 'root', '', 'api_db', '3306'); // Insert fail 10016 if (!$con) {