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.
An example of the code is presented below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// 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); |
Run Code
Click the Run Example button to try out this code example.
Documentation
Click the Webhelp button to view the application help documentation.