Skip to content

Instantly share code, notes, and snippets.

@micc83
Last active December 19, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micc83/5875218 to your computer and use it in GitHub Desktop.
Save micc83/5875218 to your computer and use it in GitHub Desktop.
Find current client IP
<?php
/**
* Trova l'ip del cliente
*/
function mc_get_user_ip() {
// Tiro giù l'ip del client
if ( isset( $_SERVER["REMOTE_ADDR"] ) ) {
$ip = $_SERVER["REMOTE_ADDR"];
} elseif ( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif ( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$ip = '1.1.1.1';
}
return $ip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment