This simple application uses several built in PHP functions to determine and then display the public IP address of the device that is being used to load the web page.
| function getUserIP() |
Copy Code |
|---|---|
// Return current IP address. function getUserIP { if(!empty($_SERVER['HTTP_CLIENT_IP'])) { //ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //ip pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } } return($ip); | |