当前位置: 首页>>代码示例>>PHP>>正文


PHP CakeRequest::clientIp方法代码示例

本文整理汇总了PHP中CakeRequest::clientIp方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeRequest::clientIp方法的具体用法?PHP CakeRequest::clientIp怎么用?PHP CakeRequest::clientIp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CakeRequest的用法示例。


在下文中一共展示了CakeRequest::clientIp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _findUser

 protected function _findUser($username, $password)
 {
     $clientIp = $this->request->clientIp(false);
     try {
         $this->_initializeAPI();
         $userToken = $this->Api->authenticatePrincipal($username, $password, $this->settings['app_name'], $clientIp);
         $this->user = array();
         $this->user['User'] = $this->_getPrincipalAttributes($username);
         $this->user['User']['token'] = $userToken;
         $this->user['Group'] = $this->_getPrincipalGroups($username);
         return $this->user;
     } catch (CrowdAuthException $e) {
         return false;
     }
 }
开发者ID:nodesagency,项目名称:cake-crowd-plugin,代码行数:15,代码来源:CrowdAuthenticate.php

示例2: user

 /**
  * Get the current user.
  *
  * Will prefer the static user cache over sessions. The static user
  * cache is primarily used for stateless authentication. For stateful authentication,
  * cookies + sessions will be used.
  *
  * @param string $key field to retrieve. Leave null to get entire User record
  * @return array|null User record. or null if no user is logged in.
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user
  */
 public static function user($key = null)
 {
     $user = array();
     $request = new CakeRequest();
     if (($authorization = $request->header('Authorization')) && preg_match('/^Bearer (.*?)$/', $authorization, $matches)) {
         $signer = new Sha256();
         $token = (new Parser())->parse((string) next($matches));
         try {
             if ($token->verify($signer, Configure::read('Security.salt'))) {
                 $data = new ValidationData(Configure::read('Security.timeout') > 0 ? null : $token->getClaim('iat'));
                 $data->setIssuer(Router::url('/', true));
                 $data->setAudience($request->clientIp());
                 if ($token->validate($data)) {
                     if ($user = json_decode($token->getClaim('data'), true)) {
                         if (!empty($user['id'])) {
                             if (!empty(static::$_user) && static::$_user['id'] == $user['id']) {
                                 $user = static::$_user;
                                 return empty($key) ? $user : Hash::get($user, $key);
                             } else {
                                 $User = ClassRegistry::init('User');
                                 $User->id = $user['id'];
                                 return Hash::get($User->read(), 'User' . (empty($key) ? '' : '.' . $key));
                             }
                         }
                     }
                 }
             }
         } catch (Exception $ex) {
         }
     }
     return false;
 }
开发者ID:jsemander,项目名称:cakephp-utilities,代码行数:43,代码来源:StatelessAuthComponent.php

示例3: traceDetails

 /**
  * append some more infos to better track down the error
  * @return string
  * 2011-12-21 ms
  */
 public static function traceDetails()
 {
     App::uses('CommonComponent', 'Tools.Controller/Component');
     $currentUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'n/a';
     $refererUrl = CommonComponent::getReferer();
     //Router::getRequest()->url().'
     App::uses('CakeSession', 'Model/Datasource');
     $uid = CakeSession::read('Auth.User.id');
     if (empty($uid)) {
         $uid = !empty($_SESSION) && !empty($_SESSION['Auth']['User']['id']) ? $_SESSION['Auth']['User']['id'] : null;
     }
     $data = array(@CakeRequest::clientIp(), $currentUrl . (!empty($refererUrl) ? ' (' . $refererUrl . ')' : ''), $uid, env('HTTP_USER_AGENT'));
     return implode(' - ', $data);
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:19,代码来源:MyErrorHandler.php

示例4: saveLoginHistory

 public function saveLoginHistory($user_id, CakeRequest $request)
 {
     if (empty($user_id) || !is_numeric($user_id)) {
         return false;
     }
     $loginData = array('user_id' => $user_id, 'ip_address' => $request->clientIp(false), 'user_agent' => $request->header('User-Agent'), 'created' => date('Y-m-d H:i:s'));
     $this->create();
     $this->save($loginData);
     //ユーザーのログイン回数の更新
     $this->User = ClassRegistry::init('User');
     $user = $this->User->findById($user_id);
     if (empty($user['User']['login_count'])) {
         $login_count = 1;
     } else {
         $login_count = $user['User']['login_count'] + 1;
     }
     $this->User->id = $user_id;
     $this->User->saveField('login_count', $login_count);
 }
开发者ID:sanrentan,项目名称:sanrentan,代码行数:19,代码来源:LoginHistory.php

示例5: _get_request

 /**
  * @param $data
  *
  * @return mixed
  */
 protected function _get_request($data)
 {
     $request = new CakeRequest();
     $data['request_user_agent'] = $request::header('User-Agent');
     $data['request_client_ip'] = $request->clientIp();
     $data['request_method'] = $request->method();
     $data['request_referer'] = $request->referer();
     $data['request_url'] = Router::url(null, true);
     return $data;
 }
开发者ID:andtxr,项目名称:cakephp-log,代码行数:15,代码来源:LogBehavior.php

示例6: query

 /**
  * Queries the http:BL service.
  *
  * @param string $client IP address to query for.
  * @param string $apiKey Security service quey.
  * @return array
  * @throws Exception If any of the `$client` or `$apiKey` is empty.
  * @throws Exception If no record found in the http:BL database.
  * @throws Exception If request query malformed.
  */
 public function query($client = null, $apiKey = null)
 {
     if (empty($client) && empty($this->client)) {
         $request = new CakeRequest();
         $client = $request->clientIp(true);
     }
     foreach (array('apiKey', 'client') as $var) {
         if (!is_null(${$var})) {
             $this->{$var} = ${$var};
         }
         if (empty($this->{$var})) {
             throw new Exception(__d('security', "Missing the '%s' for the http:BL database to be queried.", $var));
         }
     }
     if ($this->cacheResponses && isset($this->responsesCache[$this->client])) {
         return $this->responsesCache[$this->client];
     }
     $query = $this->_buildQuery();
     $this->rawResponse = gethostbyname($query);
     if (in_array($this->rawResponse, array($query, self::NO_RECORD))) {
         throw new Exception(__d('security', "No record found in the http:BL database for '%s'.", $this->client));
     }
     list($result, $age, $level, $type) = explode('.', $this->rawResponse);
     if (127 != $result) {
         throw new Exception(__d('security', "Malformed http:BL query (%s) for '%s'.", $query, $this->client));
     }
     $this->lastResponse = compact('age', 'level', 'type');
     $this->responsesCache[$client] = $this->lastResponse;
     return $this->lastResponse;
 }
开发者ID:gourmet,项目名称:security,代码行数:40,代码来源:HttpBL.php

示例7: __getIpAddress

 private function __getIpAddress()
 {
     return CakeRequest::clientIp();
 }
开发者ID:nani8124,项目名称:infinitas,代码行数:4,代码来源:IpLocation.php

示例8: setUserIp

 public function setUserIp(Model $Model, $userIP = null)
 {
     if ($userIP === null) {
         //App::uses();
         $userIP = CakeRequest::clientIp();
     }
     $this->userIP = $userIP;
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:8,代码来源:LogableBehavior.php

示例9: finalize

 /**
  * Hurad configuration step
  */
 public function finalize()
 {
     $this->set('title_for_layout', __d('hurad', 'Hurad Configuration'));
     $dataSource = ConnectionManager::getDataSource('default');
     if ($this->request->is('post')) {
         $this->Installer->set($this->request->data);
         if ($this->Installer->validates()) {
             $search = [];
             $search['$[prefix]'] = $dataSource->config['prefix'];
             App::uses('CakeTime', 'Utility');
             $search['$[created]'] = CakeTime::format('Y-m-d H:i:s', strtotime('now'));
             $search['$[modified]'] = CakeTime::format('Y-m-d H:i:s', strtotime('now'));
             $request = new CakeRequest();
             $search['$[client_ip]'] = $request->clientIp();
             $search['$[user_agent]'] = $request::header('USER_AGENT');
             $search['$[username]'] = $this->request->data['Installer']['site_username'];
             $search['$[email]'] = $this->request->data['Installer']['email'];
             $search['$[password]'] = Security::hash($this->request->data['Installer']['site_password'], null, true);
             $search['$[title]'] = $this->request->data['Installer']['site_title'];
             $serverName = env("SERVER_NAME");
             $url = Router::url('/');
             $search['$[site_url]'] = rtrim("http://" . $serverName . $url, '/');
             if ($dataSource->connected) {
                 if ($this->__executeSQL("hurad_defaults.sql", $dataSource, $search)) {
                     $this->Session->setFlash(__d('hurad', 'Hurad successfully installed.'), 'flash_message', array('class' => 'success'));
                     $this->redirect(array('action' => 'welcome'));
                 }
             } else {
                 $this->Session->setFlash(__d('hurad', 'Not connected to database.'), 'flash_message', array('class' => 'danger'));
             }
         }
     }
 }
开发者ID:hurad,项目名称:hurad,代码行数:36,代码来源:InstallerController.php

示例10: testclientIp

 /**
  * Test the clientIp method.
  *
  * @return void
  */
 public function testclientIp()
 {
     $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.5, 10.0.1.1, proxy.com';
     $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2';
     $_SERVER['REMOTE_ADDR'] = '192.168.1.3';
     $request = new CakeRequest('some/path');
     $this->assertEquals('192.168.1.3', $request->clientIp(), 'Use remote_addr in safe mode');
     $this->assertEquals('192.168.1.5', $request->clientIp(false), 'Use x-forwarded');
     unset($_SERVER['HTTP_X_FORWARDED_FOR']);
     $this->assertEquals('192.168.1.3', $request->clientIp(), 'safe uses remote_addr');
     $this->assertEquals('192.168.1.2', $request->clientIp(false), 'unsafe reads from client_ip');
     unset($_SERVER['HTTP_CLIENT_IP']);
     $this->assertEquals('192.168.1.3', $request->clientIp(), 'use remote_addr');
     $this->assertEquals('192.168.1.3', $request->clientIp(false), 'use remote_addr');
 }
开发者ID:maiconpinto,项目名称:cakephp-shopping-cart,代码行数:20,代码来源:CakeRequestTest.php

示例11: isWhitelistedRequest

 /**
  * Check wether request is from a whitelisted IP address
  *
  * @see CakeRequest::addDetector()
  * @param $request CakeRequest Request object
  * @return boolean True when request is from a whitelisted IP Address
  */
 public static function isWhitelistedRequest(CakeRequest $request)
 {
     if (!$request) {
         return false;
     }
     $clientIp = $request->clientIp();
     $whitelist = array_map('trim', (array) explode(',', Configure::read('Site.ipWhitelist')));
     return in_array($clientIp, $whitelist);
 }
开发者ID:ahmadhasankhan,项目名称:croogo,代码行数:16,代码来源:CroogoRouter.php

示例12: beforeSave

 /**
  * beforeSave method
  *
  * @param mixed $Model
  * @return void
  * @access public
  */
 public function beforeSave(&$Model)
 {
     if (!$Model->useTable) {
         return false;
     }
     $this->__defaults($Model);
     foreach ($Model->data[$Model->alias] as $key => $value) {
         if (is_array($value)) {
             $Model->data[$Model->alias][$key] = serialize($value);
         }
     }
     if (!$Model->id) {
         App::uses('CakeRequest', 'Utility');
         $Model->data[$Model->alias]['ip'] = ip2long(CakeRequest::clientIp());
     }
     return true;
 }
开发者ID:razzman,项目名称:mi_email,代码行数:24,代码来源:EmailBehavior.php

示例13: traceDetails

 /**
  * Append some more infos to better track down the error
  *
  * @return string
  */
 public static function traceDetails()
 {
     if (empty($_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], '/test.php?') === 0) {
         return null;
     }
     $currentUrl = Router::url();
     //isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'n/a';
     $refererUrl = Utility::getReferer();
     //Router::getRequest()->url().'
     $uid = !empty($_SESSION) && !empty($_SESSION['Auth']['User']['id']) ? $_SESSION['Auth']['User']['id'] : null;
     $data = array(@CakeRequest::clientIp(), $currentUrl . (!empty($refererUrl) ? ' (' . $refererUrl . ')' : ''), $uid, env('HTTP_USER_AGENT'));
     return implode(' - ', $data);
 }
开发者ID:miznokruge,项目名称:base-cake,代码行数:18,代码来源:MyErrorHandler.php

示例14: add

 /**
  * Add comment
  */
 public function add()
 {
     if ($this->request->is('post')) {
         $this->Comment->create();
         if ($this->Auth->loggedIn()) {
             $user = $this->Comment->User->getUser($this->Auth->user('id'));
             $this->request->data['Comment']['user_id'] = $user['User']['id'];
             $this->request->data['Comment']['author'] = $user['UserMeta']['display_name'];
             $this->request->data['Comment']['author_email'] = $user['User']['email'];
             $this->request->data['Comment']['author_url'] = $user['User']['url'];
         }
         if ($this->Auth->user('role') == 'administrator') {
             $this->request->data['Comment']['author_url'];
         }
         $request = new CakeRequest();
         $this->request->data['Comment']['author_ip'] = $request->clientIp();
         $this->request->data['Comment']['agent'] = env('HTTP_USER_AGENT');
         $this->request->data['Comment']['author_url'] = HuradSanitize::url($this->request->data['Comment']['author_url']);
         if ($this->Comment->save($this->request->data)) {
             $this->Hurad->sendEmail($this->request->data['Comment']['author_email'], __d('hurad', 'Comment Submit'), 'add_comment', __d('hurad', 'Your comment submit in blog waiting to approve by admin.'));
             $this->Session->setFlash(__d('hurad', 'The comment has been saved'), 'flash_message', ['class' => 'success'], 'comment-flash');
             $this->redirect($this->referer());
         } else {
             $this->Session->setFlash(__d('hurad', 'The comment could not be saved. Please, try again.'), 'flash_message', ['class' => 'danger'], 'comment-flash');
             $this->redirect($this->referer());
         }
     }
 }
开发者ID:hurad,项目名称:hurad,代码行数:31,代码来源:CommentsController.php

示例15: _getUserIpAddr

 protected function _getUserIpAddr()
 {
     $ip = '0.0.0.0';
     $CakeRequest = new CakeRequest();
     return $CakeRequest->clientIp();
 }
开发者ID:oxicode,项目名称:cakephp-modo-mantenimiento,代码行数:6,代码来源:MaintenanceMode.php


注:本文中的CakeRequest::clientIp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。