本文整理汇总了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);
}
}
示例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;
}
示例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));
}
示例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());
}
示例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);
}
}
示例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;
}