QuestionsGet the client IP address PHP
mmWebetutorial Staff asked 2 weeks ago

// Function to get the client IP address
function get_client_ip() {
$ipaddress = ”;
if (isset($_SERVER[‘HTTP_CLIENT_IP’])){
$ipaddress = $_SERVER[‘HTTP_CLIENT_IP’];
}else if(isset($_SERVER[‘HTTP_X_FORWARDED_FOR’])){
$ipaddress = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
}else if(isset($_SERVER[‘HTTP_X_FORWARDED’])){
$ipaddress = $_SERVER[‘HTTP_X_FORWARDED’];
}else if(isset($_SERVER[‘HTTP_FORWARDED_FOR’])){
$ipaddress = $_SERVER[‘HTTP_FORWARDED_FOR’];
}else if(isset($_SERVER[‘HTTP_FORWARDED’])){
$ipaddress = $_SERVER[‘HTTP_FORWARDED’];
}else if(isset($_SERVER[‘REMOTE_ADDR’])){
$ipaddress = $_SERVER[‘REMOTE_ADDR’];
$ipaddress = ‘UNKNOWN’;

return $ipaddress;

//end client ip

Your Answer
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.