Get user IP address

Sometimes we want to get the user ip address right away for verification purposes. This is the most efficient version that I found online.


if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
} else {
    $ip = $_SERVER['REMOTE_ADDR'];

Be the first to comment “Get user IP address”

This site uses Akismet to reduce spam. Learn how your comment data is processed.