本文整理匯總了PHP中Http::getClientIp方法的典型用法代碼示例。如果您正苦於以下問題:PHP Http::getClientIp方法的具體用法?PHP Http::getClientIp怎麽用?PHP Http::getClientIp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Http
的用法示例。
在下文中一共展示了Http::getClientIp方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ajaxSubmitAction
public function ajaxSubmitAction()
{
$username = Request::getPOST('username');
$password = Request::getPOST('password');
$verify = Request::getPOST('verify');
if (!Regex::match($username, RegexVars::USERNAME)) {
$this->renderAjax(1, '用戶名格式不正確!');
}
// 校驗密碼格式
if (!Regex::match($password, RegexVars::PASSWORD)) {
$this->renderAjax(1, '密碼長度為6-20位!');
}
// 校驗驗證碼
$code = Session::get('check_code');
if (strtolower($verify) != $code) {
$this->renderAjax(1, '驗證碼錯誤,請重試!');
}
// 過濾用戶名
if (false !== strpos(strtolower($username), 'admin')) {
$this->renderAjax(1, '用戶已經存在!');
}
// 校驗用戶是否存在
$userInfo = UcUserInterface::getByLoginName(array('login_name' => $username));
if (!empty($userInfo)) {
$this->renderAjax(1, '用戶名已經被占用!');
}
// 保存
$data = array('username' => $username, 'password' => $password, 'reg_ip' => Http::getClientIp());
UcUserInterface::save($data);
$this->renderAjax(0);
}
示例2: makeCode
private static function makeCode()
{
$ip = Http::getClientIp();
$ip = $ip % 1000000;
$code = rand(100000, 999999);
$code = ($code + $ip) % 1000000;
return sprintf('%06d', $code);
}
示例3: insert
private static function insert($tag, $level, $msg)
{
// 是否需要Logger
if (!GlobalConfig::$LOGGER_ENABLE) {
return;
}
// 臨時關閉Logger
$tmpEnable = GlobalConfig::$LOGGER_ENABLE;
GlobalConfig::$LOGGER_ENABLE = false;
// 校驗tag
$tags = LoggerKeys::$allTags;
if (!in_array($tag, $tags)) {
throw new LibraryException("TAG:{$tag} 需要在LoggerKeys中定義!");
}
// 獲取錯誤信息
if (is_subclass_of($msg, 'Exception')) {
$traceList = $msg->getTrace();
$message = $msg->getMessage();
$traceInfo = $traceList[0];
$loc = $traceInfo['file'] . ':' . $traceInfo['line'];
} else {
$traceList = debug_backtrace();
$message = $msg;
$traceInfo = $traceList[1];
$loc = $traceInfo['file'] . ':' . $traceInfo['line'];
}
$now = time();
$data = array('create_time' => $now, 'update_time' => $now, 'tag' => $tag, 'level' => $level, 'client_ip' => Http::getClientIp(), 'client_port' => Http::getClientPort(), 'server_ip' => Http::getServerIp(), 'server_port' => Http::getServerPort(), 'url' => Url::getCurrentUrl(), 'post' => json_encode($_POST), 'loc' => $loc, 'message' => $message, 'trace' => json_encode($traceList));
if (GlobalConfig::$LOGGER_ASYNC) {
$gearman = GearmanPool::getClient(GearmanConfig::$SERVER_COMMON);
$gearman->doBackground('logger_async', json_encode($data));
} else {
LoggerInterface::save($data);
}
GlobalConfig::$LOGGER_ENABLE = $tmpEnable;
}
示例4: makeTicket
private static function makeTicket()
{
$ticket = md5(Http::getClientIp() . Time::ms() . uniqid());
return $ticket;
}
示例5: save
public static function save($data, $id = 0, $trans = null)
{
if (0 == $id) {
$globalId = $data['global_id'];
$language = $data['language'];
$userId = $data['user_id'];
$source = $data['source'];
$contestId = Arr::get('contest_id', $data, 0);
// 設置默認語言
Cookie::set('default_language', $language, time() + 365 * 86400);
$problemInfo = OjProblemInterface::getById(array('id' => $globalId));
if (empty($problemInfo)) {
throw new InterfaceException('題目不存在!');
}
if (!array_key_exists($data['language'], StatusVars::$LANGUAGE_SUPPORT[$problemInfo['remote']])) {
throw new InterfaceException('編譯器不支持!');
}
// 連續提交判斷
if (self::submitAlready($userId)) {
throw new InterfaceException('提交頻繁!');
}
// 非法字符判斷
if ($problemInfo['remote'] == StatusVars::REMOTE_HDU) {
if (false === iconv('UTF-8', 'GBK', $source)) {
throw new InterfaceException('代碼中存在非法字符!');
}
}
// 開始事務
$innerTrans = $trans;
if (null == $trans) {
$innerTrans = new Trans(DbConfig::$SERVER_TRANS);
$innerTrans->begin();
}
$solutionModel = new OjSolutionModel($innerTrans);
$submitTime = time();
$data = array('problem_global_id' => $globalId, 'remote' => $problemInfo['remote'], 'problem_id' => $problemInfo['problem_id'], 'problem_code' => $problemInfo['problem_code'], 'user_id' => $userId, 'submit_time' => $submitTime, 'submit_ip' => Http::getClientIp(), 'language' => $language, 'result' => StatusVars::QUEUE, 'code_length' => strlen($source), 'remote_uid' => -1);
$userInfo = UserCommonInterface::getById(array('id' => $userId));
if (0 == $contestId) {
$solutionId = $solutionModel->insert($data);
UserCommonInterface::save(array('trans' => $innerTrans, 'id' => $userId, 'submit_all' => $userInfo['submit_all'] + 1));
OjProblemInterface::save(array('trans' => $innerTrans, 'id' => $problemInfo['id'], 'submit' => $problemInfo['submit']));
} else {
$contestInfo = OjContestInterface::getDetail(array('id' => $contestId));
if (empty($contestInfo)) {
throw new InterfaceException('競賽不存在!');
}
if ($submitTime > $contestInfo['end_time']) {
throw new InterfaceException('比賽已經結束!');
}
if ($submitTime < $contestInfo['begin_time']) {
throw new InterfaceException('比賽未開始!');
}
// 獲取當前的submit_order
$lastRow = OjSolutionInterface::getRow(array('where' => array(array('contest_id', '=', $contestId)), 'order' => array('id' => 'DESC')));
$data['contest_id'] = $contestId;
$data['contest_submit_order'] = empty($lastRow) ? 1 : intval($lastRow['contest_submit_order']) + 1;
$data['contest_submit_second'] = $submitTime - $contestInfo['begin_time'];
$data['contest_end_time'] = $contestInfo['end_time'];
$solutionId = $solutionModel->insert($data);
// 激活比賽
if (!$contestInfo['is_active']) {
OjContestInterface::save(array('id' => $contestId, 'trans' => $innerTrans, 'is_active' => 1));
}
}
// 如果是HQU題庫,加入隊列
if ($problemInfo['remote'] == StatusVars::REMOTE_HQU) {
OjJudgeInterface::save(array('trans' => $innerTrans, 'problem_id' => $problemInfo['problem_id'], 'language' => $language, 'source' => $source, 'user_id' => $userId, 'solution_id' => $solutionId));
}
// 保存代碼
OjSolutionCodeInterface::save(array('trans' => $innerTrans, 'solution_id' => $solutionId, 'source' => $source));
if (null == $trans && null != $innerTrans) {
// 沒有外部事務,並且存在內部事務
$innerTrans->commit();
}
// 設置重複提交緩存
$memcached = MemcachedPool::getMemcached(MemcachedConfig::$SERVER_COMMON);
$key = MemcachedKeys::OJ_SECOND_SUBMIT_ . $userId;
$memcached->set($key, true, time() + 5);
return $solutionId;
} else {
// 開始事務
$innerTrans = $trans;
if (null == $trans && array_key_exists('result', $data)) {
// 開啟內部事務條件
$innerTrans = new Trans(DbConfig::$SERVER_TRANS);
$innerTrans->begin();
}
$model = new OjSolutionModel($innerTrans);
if (array_key_exists('result', $data)) {
self::updateResult($id, $data['result'], $innerTrans);
unset($data['result']);
}
// 對某些字段特殊處理
$updateData = $data;
$affects = $model->updateById($id, $updateData);
if (null == $trans && null != $innerTrans) {
// 沒有外部事務,並且存在內部事務
$innerTrans->commit();
}
return $affects;
//.........這裏部分代碼省略.........