php - $_SERVER['REMOTE_ADDR'] is not giving ip address in wordpress plugin -


i'm building plugin wordpress create new payment gateway in woocommerce. in plugin, need send clients ip address api.

well, $_server['remote_addr'] not giving me correct ip address when use in plugins php file. wc_geolocation::get_ip_address() not working too, both of them giving me servers ip if use them in plugin file. if use them in footer.php, gives me correct ip address. so, must not server configuration, actually, when try display clients ip in receipt page, in receipt section both of them gives me servers ip while give me correct ip in footer.

what causes display servers ip address when using $_server['remote_addr']?

are there alternatives?

you can use function:

// function client ip address static function get_client_ip() {     $ipaddress = '';     if (isset($_server['http_client_ip'])) {         $ipaddress .= $_server['http_client_ip'] . ' - ';     }     if(isset($_server['http_x_forwarded_for'])) {         $ipaddress .= $_server['http_x_forwarded_for']. ' - ';     }     if(isset($_server['http_x_forwarded'])) {         $ipaddress .= $_server['http_x_forwarded']. ' - ';     }     if(isset($_server['http_forwarded_for'])) {         $ipaddress .= $_server['http_forwarded_for']. ' - ';     }     if(isset($_server['http_forwarded'])) {         $ipaddress .= $_server['http_forwarded']. ' - ';     }     if(isset($_server['remote_addr'])) {         $ipaddress .= $_server['remote_addr']. ' - ';     }      if($ipaddress == '') {         $ipaddress = 'unknown';     }      return $ipaddress; } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -