You are here

public function ShareaholicShareCount::get_client_ip in Share Buttons, Related Posts, Content Analytics - Shareaholic 7.3

Same name and namespace in other branches
  1. 8 lib/social-share-counts/share_count.php \ShareaholicShareCount::get_client_ip()

Get the client's ip address

NOTE: this function does not care if the IP is spoofed. This is used only by the google plus count API to separate server side calls in order to prevent usage limits. Under normal conditions, a request from a user's browser to this API should not involve any spoofing.

Return value

{Mixed} An IP address as string or false otherwise

File

lib/social-share-counts/share_count.php, line 133

Class

ShareaholicShareCount
An abstract class Share Counts to be extended

Code

public function get_client_ip() {
  $ip = NULL;
  if (!empty($_SERVER['HTTP_CLIENT_IP'])) {

    //check for ip from share internet
    $ip = $_SERVER['HTTP_CLIENT_IP'];
  }
  elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {

    // Check for the Proxy User
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
  else {
    $ip = $_SERVER['REMOTE_ADDR'];
  }
  return $ip;
}