Example #1
0
 /**
  * Gets the External IP using an external service, it is cached
  *
  * @param bool $force default false, force IP check even when cached
  *
  * @return string
  */
 public static function getIP($force = false)
 {
     if (Utils::$online === false) {
         return false;
     } elseif (Utils::$ip !== false and $force !== true) {
         return Utils::$ip;
     }
     $ip = trim(strip_tags(Utils::getURL("http://checkip.dyndns.org/")));
     if (preg_match('#Current IP Address\\: ([0-9a-fA-F\\:\\.]*)#', $ip, $matches) > 0) {
         Utils::$ip = $matches[1];
     } else {
         $ip = Utils::getURL("http://www.checkip.org/");
         if (preg_match('#">([0-9a-fA-F\\:\\.]*)</span>#', $ip, $matches) > 0) {
             Utils::$ip = $matches[1];
         } else {
             $ip = Utils::getURL("http://checkmyip.org/");
             if (preg_match('#Your IP address is ([0-9a-fA-F\\:\\.]*)#', $ip, $matches) > 0) {
                 Utils::$ip = $matches[1];
             } else {
                 $ip = trim(Utils::getURL("http://ifconfig.me/ip"));
                 if ($ip != "") {
                     Utils::$ip = $ip;
                 } else {
                     return false;
                 }
             }
         }
     }
     return Utils::$ip;
 }