How to Get User IP Address in PHP?
Hello Friends,
This tutorial is focused on how to get user ip address in php. This article goes in detailed on how to get ip address in php. We will use how to get server ip address in php. We will use how to get client ip address in php. Here, Create a basic example of php get ip address from request.
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.
index.php
<?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 if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else{
$ipAddress = 'UnKnown';
}
return $ipAddress;
}
$ip = getClientIp();
echo 'User Real IP Address - '.$ip;
?>
Output:
User Real IP Address - 127.0.0.0
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get IP Address in JQuery?
- How to Get a Current Page URL in PHP?
- How to Get the File Size in PHP?
- How to Get php.ini File Path in Ubuntu?
- How to Check If String is URL or Not in PHP?
- How to Convert Array Key to Lowercase in PHP?
- How to Convert Array Values to Lowercase in PHP?
- How to Get IP Address in Laravel?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Count Number of Files in a Directory in PHP?
- How to Find Day Name from Specific Date in PHP?
- How to Remove Null Values from Array in PHP?
- Which MySQL Datatype use for Store an IP Address?