Interactive

Web Development Services

Get user IP address

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.

Copy PHP

//Ref: http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php

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

comments

no comments...

Leave A Comment

Don’t wait! Your customers are surfing the Web right now. Get your website up today.

get in touch