/** * 获取真实HTTP客户端IP,按次序尝试 * * @return string */ public static function getClientIP() { if (strlen(self::$client_ip) < 7) { self::$client_ip = IP::getClientIP(); } return self::$client_ip; }
public static function insteadOfURL(&$url) { $hostname = parse_url($url, PHP_URL_HOST); if ($ipaddr = IP::getHostIP($hostname)) { $url = str_ireplace($hostname, $ipaddr, $url); } return $hostname; }
/** * 将IP对象或字符串ip转为HEX格式 */ public static function formatIP($ipaddr) { return IP::toHex($ipaddr); }
<?php use Cute\Utility\IP; use Cute\Network\JobServer; app()->route('/', function () { $job_server = JobServer::getInstance(); $job_server->setWorkerFile(APP_ROOT . '/workers/geo_worker.php'); var_dump($job_server->reverse('Hello World')); var_dump($job_server->reverse('Hello', 'World')); $ipaddr = IP::getServerIP(); var_dump($ipaddr); var_dump($job_server->ip_search_country($ipaddr)); var_dump($job_server->ip_search_address($ipaddr)); var_dump($job_server->phone_search_city('0035818', '028', '18475870001')); });
public static function getClientIP() { return IP::getClientIP(); }