Php function to obtain the online ip address and client ip address
/**
- * Obtain the client ip address
- * @ Return [string] [description]
- */
- Function getclientip (){
- $ Ip = null;
- If (isset ($ _ server ['http _ x_forwarded_for ']) {
- $ Arr = explode (',', $ _ server ['http _ x_forwarded_for ']);
- $ Pos = array_search ('Unknown ', $ arr );
- If (false! ==$ Pos) unset ($ arr [$ pos]);
- $ Ip = trim ($ arr [0]);
- } Elseif (isset ($ _ server ['http _ client_ip ']) {
- $ Ip = $ _ server ['http _ client_ip '];
- } Elseif (isset ($ _ server ['remote _ addr ']) {
- $ Ip = $ _ server ['remote _ addr '];
- }
- // Valid IP Address Verification
- $ Ip = (false! = Ip2long ($ ip ))? $ Ip: '0. 0.0.0 ';
- Return $ ip;
- }
/**
- * Getting an online ip address
- * @ Return string
- */
- Function getonlineip ($ format = 0 ){
- Global $ s_global;
- If (empty ($ s_global ['onlineip']) {
- If (getenv ('http _ client_ip ') & strcasecmp (getenv ('http _ client_ip'), 'Unknown ')){
- $ Onlineip = getenv ('http _ client_ip ');
- } Elseif (getenv ('http _ x_forwarded_for ') & strcasecmp (getenv ('http _ x_forwarded_for'), 'Unknown ')){
- $ Onlineip = getenv ('http _ x_forwarded_for ');
- } Elseif (getenv ('remote _ addr ') & strcasecmp (getenv ('remote _ addr'), 'Unknown ')){
- $ Onlineip = getenv ('remote _ addr ');
- } Elseif (isset ($ _ server ['remote _ addr ']) & $ _ server ['remote _ addr '] & strcasecmp ($ _ server ['remote _ addr'], 'Unknown ')){
- $ Onlineip = $ _ server ['remote _ addr '];
- }
- Preg_match ("/[\ d \.] {7, 15}/", $ onlineip, $ onlineipmatches );
- $ S_global ['onlineip'] = $ onlineipmatches [0]? $ Onlineipmatches [0]: 'Unknown ';
- }
If ($ format ){
- $ Ips = explode ('.', $ s_global ['onlineip']);
- For ($ I = 0; $ I <3; $ I ++ ){
- $ Ips [$ I] = intval ($ ips [$ I]);
- }
- Return sprintf ('% 03d % 03d % 03d', $ ips [0], $ ips [1], $ ips [2]);
- } Else {
- Return $ s_global ['onlineip'];
- }
- }
Php: obtaining the real IP address of a remote client php method for obtaining the public ip address on an intranet machine php simple example for reading a pure IP database PHP method for obtaining the local LAN ip address PHP method for obtaining the computer name, IP address and MAC address on a LAN address PHP multiple ways to get IP addresses PHP code to get geographic location through IP address PHP get specified IP address segment information php IP get City API (pure IP database) php instance for obtaining real IP addresses: PHP method for obtaining domain names and domain name IP addresses php example for Obtaining geographic locations through IP address reference |