6.7 C
New York
Wednesday, March 22, 2023

How to get ip address using php code?





Whenever you require to get current user ip address then bellow example will help you. you can find client ip address using $_SERVER variable in php. As you can see bellow example how to find use ip address.

Example:

<?php


function getClientIp() {

$ipAddress = '';

if (isset($_SERVER['HTTP_CLIENT_IP'])){

$ipAddress = $_SERVER['HTTP_CLIENT_IP'];

} else if(isset($_SERVER['REMOTE_ADDR'])){

$ipAddress = $_SERVER['REMOTE_ADDR'];

}else{

$ipAddress = 'UnKnown';

}

return $ipAddress;

}


echo getClientIp();

?>

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles