FOF30\Utils\Ip::getIp PHP Method

getIp() public static method

Get the current visitor's IP address
public static getIp ( ) : string
return string
    public static function getIp()
    {
        if (is_null(static::$ip)) {
            $ip = self::detectAndCleanIP();
            if (!empty($ip) && $ip != '0.0.0.0' && function_exists('inet_pton') && function_exists('inet_ntop')) {
                $myIP = @inet_pton($ip);
                if ($myIP !== false) {
                    $ip = inet_ntop($myIP);
                }
            }
            static::setIp($ip);
        }
        return static::$ip;
    }

Usage Example

Esempio n. 1
0
 public function check()
 {
     if (empty($this->user_id)) {
         $user = $this->container->platform->getUser();
         $this->user_id = $user->id;
     }
     if (empty($this->item_id)) {
         // Yeah, I know, the Model shouldn't access the input directly but this saves us a lot of code in the
         // front-end models where we're logging downloads.
         $this->item_id = $this->input->getInt('id', 0);
     }
     if (empty($this->accessed_on) || $this->accessed_on == '0000-00-00 00:00:00') {
         \JLoader::import('joomla.utilities.date');
         $date = new \JDate();
         $this->accessed_on = $date->toSql();
     }
     if (empty($this->referer)) {
         if (isset($_SERVER['HTTP_REFERER'])) {
             $this->referer = $_SERVER['HTTP_REFERER'];
         }
     }
     if (empty($this->ip)) {
         $this->ip = Ip::getIp();
         if (class_exists('\\AkeebaGeoipProvider')) {
             $geoip = new \AkeebaGeoipProvider();
             $this->country = $geoip->getCountryCode($this->ip);
         }
     }
     return parent::check();
 }