CakeRequest::clientIp PHP Method

clientIp() public method

Get the IP the client is using, or says they are using.
public clientIp ( boolean $safe = true ) : string
$safe boolean Use safe = false when you think the user might manipulate their HTTP_CLIENT_IP header. Setting $safe = false will also look at HTTP_X_FORWARDED_FOR
return string The client IP.
    public function clientIp($safe = true)
    {
        if (!$safe && env('HTTP_X_FORWARDED_FOR')) {
            $ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
        } elseif (!$safe && env('HTTP_CLIENT_IP')) {
            $ipaddr = env('HTTP_CLIENT_IP');
        } else {
            $ipaddr = env('REMOTE_ADDR');
        }
        return trim($ipaddr);
    }

Usage Example

 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;
     }
 }
All Usage Examples Of CakeRequest::clientIp