/** * Get IP address. * * @static * @return string IP address. */ public static function get() { $sIp = ''; // Default IP address value. $aVars = [Server::HTTP_CLIENT_IP, Server::HTTP_X_FORWARDED_FOR, Server::REMOTE_ADDR]; foreach ($aVars as $sVar) { if (null !== Server::getVar($sVar)) { $sIp = Server::getVar($sVar); break; } } unset($aVars); return preg_match('/^[a-z0-9:.]{7,}$/', $sIp) ? $sIp : '0.0.0.0'; }
/** * Get IP address. * * @static * @return string IP address. If the IP format is invalid, returns '0.0.0.0' */ public static function get() { $sIp = ''; // Default IP address value. $aVars = [Server::HTTP_CLIENT_IP, Server::HTTP_X_FORWARDED_FOR, Server::REMOTE_ADDR]; foreach ($aVars as $sVar) { if (null !== Server::getVar($sVar)) { $sIp = Server::getVar($sVar); break; } } unset($aVars); if (static::isPrivate($sIp)) { $sIp = ($sIp = @file_get_contents('http://addons.hizup.com/ip/')) ? trim($sIp) : '127.0.0.1'; } return preg_match('/^[a-z0-9:.]{7,}$/', $sIp) ? $sIp : '127.0.0.1'; }
/** * Get IP address. * * @static * @return string IP address. If the IP format is invalid, returns '0.0.0.0' */ public static function get() { $sIp = ''; // Default IP address value. $aVars = [Server::HTTP_CLIENT_IP, Server::HTTP_X_FORWARDED_FOR, Server::REMOTE_ADDR]; foreach ($aVars as $sVar) { if (null !== Server::getVar($sVar)) { $sIp = Server::getVar($sVar); break; } } unset($aVars); if (static::isPrivate($sIp)) { $sIp = '127.0.0.1'; } // Avoid invalid local IP for GeoIp return preg_match('/^[a-z0-9:.]{7,}$/', $sIp) ? $sIp : '127.0.0.1'; }
/** * @static * @return string The HTTP server protocol. */ public static function getProtocol() { return Server::getVar(Server::SERVER_PROTOCOL); }
/** * @return boolean */ public function isAjaxRequest() { return array_key_exists(Server::HTTP_X_REQUESTED_WITH, Server::getVar()); }