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


PHP Request::clientIp方法代码示例

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


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

示例1: beforeLog

 /**
  * Enriches all of the passed audit logs to add the request
  * info metadata.
  *
  * @param Event The AuditStash.beforeLog event
  * @param array $logs The audit log event objects
  * @return void
  */
 public function beforeLog(Event $event, array $logs)
 {
     $meta = ['ip' => $this->request->clientIp(), 'url' => $this->request->here(), 'user' => $this->user];
     foreach ($logs as $log) {
         $log->setMetaInfo($log->getMetaInfo() + $meta);
     }
 }
开发者ID:lorenzo,项目名称:audit-stash,代码行数:15,代码来源:RequestMetadata.php

示例2: beforeSave

 public function beforeSave(Event $event, EntityInterface $entity)
 {
     if ($entity === null) {
         return true;
     }
     $isNew = $entity->isNew();
     $fields = $this->config('fields');
     $ip = self::$_request->clientIp();
     foreach ($fields as $field => $when) {
         $when = strtolower($when);
         if (!in_array($when, ['always', 'new'])) {
             throw new UnexpectedValueException(sprintf('"When" should be one of "always", "new". The passed value "%s" is invalid', $when));
         }
         switch ($when) {
             case 'always':
                 $entity->set($field, $ip);
                 continue;
                 break;
             case 'new':
                 if ($isNew) {
                     $entity->set($field, $ip);
                     continue;
                 }
                 break;
         }
     }
     return true;
 }
开发者ID:thefredfox,项目名称:cakephp-ip-behavior,代码行数:28,代码来源:IpBehavior.php

示例3: startup

 /**
  * Startup event to trace the user on the website.
  *
  * @param Event $event The event that was fired.
  *
  * @return void
  */
 public function startup(Event $event)
 {
     if (empty($this->_session->id())) {
         $this->_session->start();
         return;
     }
     $sessions = TableRegistry::get('Sessions');
     $prefix = isset($this->_request['prefix']) ? $this->_request['prefix'] . '/' : '';
     $controller = $prefix . $this->_request['controller'];
     $action = $this->_request['action'];
     $params = serialize($this->_request->pass);
     $expires = time() + ini_get('session.gc_maxlifetime');
     //@codingStandardsIgnoreStart
     $user_id = $this->_session->read('Auth.User.id');
     $user_agent = $this->_request->env('HTTP_USER_AGENT');
     $user_ip = $this->_request->clientIp();
     $full_url = $this->_request->url;
     //@codingStandardIgnoreEnd
     $modified = new Time();
     $record = compact('controller', 'action', 'params', 'expires', 'user_id', 'user_agent', 'user_ip', 'full_url', 'modified');
     $record[$sessions->primaryKey()] = $this->_session->id();
     $sessions->save(new Entity($record));
 }
开发者ID:Xety,项目名称:Xeta,代码行数:30,代码来源:SessionsActivityComponent.php

示例4: testclientIp

 /**
  * Test the clientIp method.
  *
  * @return void
  */
 public function testclientIp()
 {
     $request = new Request(['environment' => ['HTTP_X_FORWARDED_FOR' => '192.168.1.5, 10.0.1.1, proxy.com', 'HTTP_CLIENT_IP' => '192.168.1.2', 'REMOTE_ADDR' => '192.168.1.3']]);
     $request->trustProxy = true;
     $this->assertEquals('192.168.1.5', $request->clientIp());
     $request->trustProxy = false;
     $this->assertEquals('192.168.1.2', $request->clientIp());
     $request->env('HTTP_X_FORWARDED_FOR', '');
     $this->assertEquals('192.168.1.2', $request->clientIp());
     $request->env('HTTP_CLIENT_IP', '');
     $this->assertEquals('192.168.1.3', $request->clientIp());
     $request->env('HTTP_CLIENTADDRESS', '10.0.1.2, 10.0.1.1');
     $this->assertEquals('10.0.1.2', $request->clientIp());
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:19,代码来源:RequestTest.php

示例5: _resetBruteForceAttack

 /**
  * _resetBruteForceAttack
  *
  * @param \Cake\Network\Request $request The request that contains login information.
  * @return void
  */
 protected function _resetBruteForceAttack(Request $request)
 {
     $filePath = CONFIG . $this->_config['lockout']['file_path'] . DS . $request->clientIp();
     if (file_exists($filePath)) {
         unlink($filePath);
     }
 }
开发者ID:crabstudio,项目名称:authenticate,代码行数:13,代码来源:AdvanceAuthenticate.php

示例6: _requestContext

 /**
  * Get the request context for an error/exception trace.
  *
  * @param \Cake\Network\Request $request The request to read from.
  * @return string
  */
 protected function _requestContext($request)
 {
     $message = "\nRequest URL: " . $request->here();
     $referer = $request->env('HTTP_REFERER');
     if ($referer) {
         $message .= "\nReferer URL: " . $referer;
     }
     $clientIp = $request->clientIp();
     if ($clientIp && $clientIp !== '::1') {
         $message .= "\nClient IP: " . $clientIp;
     }
     return $message;
 }
开发者ID:rlugojr,项目名称:cakephp,代码行数:19,代码来源:BaseErrorHandler.php


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