How to get ip address using php code?

By Hardik Savani | May 17, 2016 | | 33046 Viewer | Category : PHP


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();

?>




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: