Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save robertobermejo/eb28f012fd02a2a76eea7d13b86720f2 to your computer and use it in GitHub Desktop.

Select an option

Save robertobermejo/eb28f012fd02a2a76eea7d13b86720f2 to your computer and use it in GitHub Desktop.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ip-api.com/json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$info = json_decode(curl_exec($ch));
$ipAddress = $_SERVER['REMOTE_ADDR'];
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
$ipAddress = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
}
echo sprintf('Your ip address is : %s<br>', $ipAddress);
echo sprintf('Mi internal ip address is : %s<br>', $_SERVER['SERVER_ADDR']);
echo sprintf('Mi external ip address is : %s<br>', $info->query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment