Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rushh's avatar
Level 1

Get User IP address

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 ?

0 likes
3 replies
rushh's avatar
Level 1

I want to use that IP address to get location details so If i use this then , i can not able o get proper data.

	        $data = \Location::get($clientIP);
frankielee's avatar

I want to use that IP address to get location details so If i use this then , i can not able o get proper data.

First of all, you didn't mention about this, what you asked is

What should I do to get IP address ?

$data = \Location::get($clientIP);

And, can you provide the link/documentation of the package?

Or you can just use this package

https://github.com/pulkitjalan/geoip

Please or to participate in this conversation.