Try
request()->ip();
$request->ip()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello all, I just try to get different users IP address using PHP/Laravel. I got some solution from internet but these are not work for me.
Here is that solution:
<?php
//whether ip is from share internet
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
//whether ip is from proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
//whether ip is from remote address
else
{
$ip_address = $_SERVER['REMOTE_ADDR'];
}
echo $ip_address;
?>
But here , I have not any type of data like , $_SERVER['HTTP_CLIENT_IP'] / $_SERVER['REMOTE_ADDR']/ $_SERVER['HTTP_X_FORWARDED_FOR'] into my .env file !
What should I do to get IP address ?
Please or to participate in this conversation.