Reputation: 58652
My current IP is : 24.62.137.161
and when I use
$ip = $request->getClientIp();
dd($ip);
I keep getting ::1
How can I grab 24.62.137.161
?
I'm not sure if what I'm trying to do if possible.
Any hints / suggestion will be much appreciated.
Upvotes: 7
Views: 12096
Reputation: 27
It is the expected result when you are in local
environment (development mode). But when the app is running in production
, you will get the public IP address that you want.
Summary base on your question:
127.0.0.1
24.62.137.161
Upvotes: -1
Reputation: 242
You Can Try This
$ip_address = file_get_contents('https://api.ipify.org');
print_r($ip_address);
Upvotes: 1
Reputation: 127
You can get the exact IP with the following function
gethostbyname(trim(hostname
))
Upvotes: -2
Reputation: 58652
$ip = trim(shell_exec("dig +short myip.opendns.com @resolver1.opendns.com"));
dd("Public IP: ".$ip); //"Public IP: 24.62.137.161"
Upvotes: 13
Reputation:
try this to Grab public IP address using Laravel,
Request::getClientIp()
Upvotes: 0