* ** Obtain the real IP address of the user ** @ accesspublic * @ returnstring * functionreal_ip () {static $ realipNULL; if ($ realip! NULL) {return $ realip;} if...
/*** Obtain the real IP address of the user ** @ access public * @ return string */function real_ip () {static $ realip = NULL; if ($ realip! = NULL) {return $ realip;} if (isset ($ _ SERVER) {if (isset ($ _ SERVER ['http _ X_FORWARDED_FOR ']) {$ arr = explode (',', $ _ SERVER ['http _ X_FORWARDED_FOR ']); /* obtain the first non-unknown valid IP string in X-Forwarded-For */foreach ($ arr AS $ ip) {$ ip = trim ($ ip ); if ($ ip! = 'Unknon') {$ realip = $ ip; break ;}} elseif (isset ($ _ SERVER ['http _ CLIENT_IP ']) {$ realip = $ _ SERVER ['http _ CLIENT_IP '];} else {if (isset ($ _ SERVER ['remote _ ADDR']) {$ realip = $ _ SERVER ['remote _ ADDR '];} else {$ realip = '0. 0.0.0 ';}} else {if (getenv ('http _ X_FORWARDED_FOR') {$ realip = getenv ('http _ X_FORWARDED_FOR ');} elseif (getenv ('http _ CLIENT_IP ') {$ realip = getenv ('http _ CLIENT_IP ');} Else {$ realip = getenv ('remote _ ADDR');} preg_match ("/[\ d \.] {7, 15}/", $ realip, $ onlineip); $ realip =! Empty ($ onlineip [0])? $ Onlineip [0]: '0. 0.0.0 '; return $ realip ;}