Obtain the real IP address of the client

Source: Internet
Author: User
Php code. You can also obtain the real ip address using the proxy server. The code is pasted from ThinkPHP and does not obtain the visitor's real ippublicfunctionGetip () {if (! Empty ($ _ SERVER [HTTP_CLIENT_IP]) {$ ip $ _ SERVER [HTTP_CLIENT_IP];} if (! Empty ($ _ SERVER [HTTP_X_FORWARDED_FOR]) {

Php code. You can also obtain the real ip address using the proxy server. The code is pasted from ThinkPHP without // obtain the real ip address of the visitor public function Getip () {if (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"]) {$ ip = $ _ SERVER ["HTTP_CLIENT_IP"];} if (! Empty ($ _ SERVER ['HTTP _ X_FORWARDED_FOR ']) {//

Php code. The real ip Address can also be obtained using the proxy server. The code is pasted from ThinkPHP. <无>
// Obtain the visitor's real ip address public function Getip () {if (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"]) {$ ip = $ _ SERVER ["HTTP_CLIENT_IP"];} if (! Empty ($ _ SERVER ['HTTP _ X_FORWARDED_FOR ']) {// get proxy ip $ ips = explode (',', $ _ SERVER ['HTTP _ X_FORWARDED_FOR ']);} if ($ ip) {$ ips = array_unshift ($ ips, $ ip );} $ count = count ($ ips); for ($ I = 0; $ I <$ count; $ I ++) {if (! Preg_match ("/^ (10 | 172 \. 16 | 192 \. (168 )\. /I ", $ ips [$ I]) {// exclude LAN ip $ ip = $ ips [$ I]; break ;}$ tip = $ ip? $ Ip: $ _ SERVER ['remote _ ADDR ']; if ($ tip = "127.0.0.1 ") {// obtain the local real IP return $ this-> get_onlineip () ;}else {return $ tip ;}// obtain the local real IP public function get_onlineip () {$ mip = file_get_contents ("http://www.ip138.com/ip2city.asp"); if ($ mip) {preg_match ("/\[. * \]/", $ mip, $ sip); $ p = array ("/\ [/","/\]/"); return preg_replace ($ p, "", $ sip [0]);} else {return "An error occurred while obtaining the local IP address! ";}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.