getIpAddress(); } $this->data = $data; } /** * isValid() - this method will determine if the current user IP matches the * IP we stored when we initialized this variable. * * @return bool */ public function isValid() { return ($this->getIpAddress() === $this->getData()); } /** * Changes proxy handling setting. * * This must be static method, since validators are recovered automatically * at session read, so this is the only way to switch setting. * * @param bool $useProxy Whether to check also proxied IP addresses. * @return void */ public static function setUseProxy($useProxy = true) { static::$useProxy = $useProxy; } /** * Checks proxy handling setting. * * @return bool Current setting value. */ public static function getUseProxy() { return static::$useProxy; } /** * Set list of trusted proxy addresses * * @param array $trustedProxies * @return void */ public static function setTrustedProxies(array $trustedProxies) { static::$trustedProxies = $trustedProxies; } /** * Set the header to introspect for proxy IPs * * @param string $header * @return void */ public static function setProxyHeader($header = 'X-Forwarded-For') { static::$proxyHeader = $header; } /** * Returns client IP address. * * @return string IP address. */ protected function getIpAddress() { $remoteAddress = new RemoteAddress(); $remoteAddress->setUseProxy(static::$useProxy); $remoteAddress->setTrustedProxies(static::$trustedProxies); $remoteAddress->setProxyHeader(static::$proxyHeader); return $remoteAddress->getIpAddress(); } /** * Retrieve token for validating call * * @return string */ public function getData() { return $this->data; } /** * Return validator name * * @return string */ public function getName() { return __CLASS__; } }