|
|
@ -372,4 +372,65 @@ eof; |
|
|
|
exit; |
|
|
|
exit; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//请求频率限制 |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* key: 检查频率限制的唯一标识 |
|
|
|
|
|
|
|
* max: 最大次数 |
|
|
|
|
|
|
|
* time: 检查时间,单位:秒 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected function requestLimit($key, $max, $time) { |
|
|
|
|
|
|
|
$isLimited = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
session_start(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$current_time = microtime(true)*1000; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$field = md5("requestLimit_by_{$key}"); |
|
|
|
|
|
|
|
$field_update_time = "{$field}_updated"; |
|
|
|
|
|
|
|
if (!empty($_SESSION[$field]) && !empty($_SESSION[$field_update_time]) && $current_time - $_SESSION[$field_update_time] <= $time*1000) { |
|
|
|
|
|
|
|
$_SESSION[$field] ++; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$_SESSION[$field] = 1; |
|
|
|
|
|
|
|
$_SESSION[$field_update_time] = $current_time; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($_SESSION[$field] > $max) { |
|
|
|
|
|
|
|
$isLimited = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}catch(Exception $e) { |
|
|
|
|
|
|
|
$this->logError("Request limit by session failed: " . $e->getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $isLimited; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取短信验证码 |
|
|
|
|
|
|
|
public function actionSendsmscode() { |
|
|
|
|
|
|
|
echo "Building..."; |
|
|
|
|
|
|
|
exit; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//新用户注册 |
|
|
|
|
|
|
|
public function actionCreateuser() { |
|
|
|
|
|
|
|
$ip = $this->getUserIp(); |
|
|
|
|
|
|
|
$check_time = 120; //2 分钟内 |
|
|
|
|
|
|
|
$max_time_in_minutes = 5; //最多 5 次 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$isUserGotRequestLimit = $this->requestLimit($ip, $max_time_in_minutes, $check_time); |
|
|
|
|
|
|
|
if ($isUserGotRequestLimit) { |
|
|
|
|
|
|
|
$this->logError("Request limit got, ip: {$ip}"); |
|
|
|
|
|
|
|
throw new Exception('Oops,操作太快了,请喝杯咖啡休息会吧...'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Building..."; |
|
|
|
|
|
|
|
exit; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//用户登录 |
|
|
|
|
|
|
|
public function actionLoginuser() { |
|
|
|
|
|
|
|
echo "Building..."; |
|
|
|
|
|
|
|
exit; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|