thinkphp»ñÈ¡ÇëÇóip
ÔÚweb¿ª·¢ÖУ¬Í¨³£ÐèÒª»ñÈ¡¿Í»§¶ËµÄipµØµã¡£¶øÔÚʹÓÃphp¿ò¼Üthinkphpʱ£¬»ñÈ¡ÇëÇóipµØµãºÜÊÇÈÝÒס£±¾ÎĽ«¼òÆÓÏÈÈÝÔõÑùÔÚthinkphp¿ò¼ÜÖлñÈ¡ÇëÇóipµØµã¡£
Ò»¡¢»ñÈ¡¿Í»§¶ËIPµØµã
»ñÈ¡¿Í»§¶ËIPµØµãÔÚÈκÎWeb¿ª·¢Öж¼ÊǽÏÁ¿³£¼ûµÄÐèÇó¡£ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ´úÂëÀ´»ñÈ¡¿Í»§¶ËIPµØµã£º
$request = hinkRequest::instance(); $ip = $request->ip();
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬ hinkRequest::instance()»ñÈ¡ÇëÇóʵÀý£¬$request->ip()»ñÈ¡ÇëÇóIPµØµã¡£
¶þ¡¢»ñÈ¡¿Í»§¶ËÕæʵIPµØµã
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÓÉÓÚ¿Í»§¶ËIPµØµã¿ÉÒÔºÜÈÝÒ×αÔ죬Òò´ËÔÚijЩ³¡¾°ÏÂÐèÒª»ñÈ¡¿Í»§¶ËÕæʵIPµØµã¡£´Ëʱ£¬ÎÒÃÇ¿ÉÒÔͨ¹ý»ñÈ¡HTTPÍ·ÖеÄX-Forwarded-ForÀ´»ñÈ¡¡£
$request = hinkRequest::instance(); $ip = $request->header('x-forwarded-for');
µÇ¼ºó¸´ÖÆ
ÕâÀïµÄx-forwarded-forÊÇHTTPÍ·ÖеÄÒ»¸ö×ֶΣ¬ËüÍùÍù°üÀ¨ÁË¿Í»§¶ËµÄÕæʵIPµØµã£¨ÈôÊÇÓжà¸öIPµØµã£¬ÔòÒÔ¶ººÅÍÑÀ룩¡£ÐèҪעÖصÄÊÇ£¬ÓÐЩÊðÀíЧÀÍÆ÷²»»áÔÚHTTPÍ·ÖÐÌí¼Óx-forwarded-for×ֶΣ¬Òò´ËÔÚijЩÇéÐÎÏÂÕâÖÖÒªÁì¿ÉÄÜÎÞ·¨»ñÈ¡¿Í»§¶ËÕæʵIPµØµã¡£
Èý¡¢»ñȡЧÀÍÆ÷IPµØµã
ÓÐʱ¼äÎÒÃÇÐèÒª»ñȡЧÀÍÆ÷IPµØµã£¬ºÃ±ÈÔÚÈ·¶¨Ä¿½ñÍøÕ¾ÔËÐÐÇéÐÎʱ¡£ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ´úÂëÀ´»ñȡЧÀÍÆ÷IPµØµã£º
$server_ip = gethostbyname($_SERVER["SERVER_NAME"]);
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬$_SERVER[“SERVER_NAME”]ÌåÏÖÄ¿½ñЧÀÍÆ÷µÄÓòÃû£¬gethostbynameº¯Êý»á·µ»Ø¸ÃÓòÃû¶ÔÓ¦µÄIPµØµã¡£
ËÄ¡¢»ñÈ¡Ä¿½ñ»á¼ûµÄURL
ÔÚWeb¿ª·¢ÖУ¬»ñÈ¡Ä¿½ñÒ³ÃæµÄURLµØµã·Ç¾³£¼û¡£ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ´úÂë»ñÈ¡Ä¿½ñÒ³ÃæµÄURL£º
$url = request()->url(true);
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬request()ÌåÏÖÇëÇ󹤾ßʵÀý£¬url(true)ÌåÏÖ»ñÈ¡ÍêÕûµÄURLµØµã¡£ÈôÊDz»×ª´ï²ÎÊý£¬ÔòĬÈÏÖ»»ñÈ¡URL·¾¶²¿·Ö£¬²»°üÀ¨ÓòÃûºÍÐÒéµÈÐÅÏ¢¡£
Î塢С½á
ÔÚThinkPHP¿ò¼ÜÖУ¬»ñÈ¡ÇëÇóIPµØµã¡¢¿Í»§¶ËÕæʵIPµØµã¡¢Ð§ÀÍÆ÷IPµØµãºÍÄ¿½ñ»á¼ûµÄURLºÜÊǼòÆÓ¡£Í¨¹ýÉÏÊö´úÂ룬ÎÒÃÇ¿ÉÒÔÇáËɵػñÈ¡ÕâЩ³£ÓÃÐÅÏ¢£¬Îª×ðÁú¿Ê±Web¿ª·¢ÊÂÇéÌṩÁ˱ã½Ý¡£
ÒÔÉϾÍÊÇthinkphp»ñÈ¡ÇëÇóipµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡