Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grab public IP address using Laravel

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.

like image 476
code-8 Avatar asked Aug 20 '15 21:08

code-8


People also ask

How can I get public IP in laravel?

For getting the IP Address we have to include use Illuminate\Http\Request; in the controller and then add the code of the below pre tag. It will give the IP address of the network. dd($request->ip()); }$clientIP = \Request::ip();

How can I get public IP address in PHP?

The simplest way to collect the visitor IP address in PHP is the REMOTE_ADDR. Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.

How do I find my server IP in laravel?

You can use request object: request()->server('SERVER_ADDR'); Or you can use standard PHP way: $_SERVER['SERVER_ADDR'];

What is $_ server [' Remote_addr ']?

$_SERVER['REMOTE_ADDR'] Returns the IP address from where the user is viewing the current page. $_SERVER['REMOTE_HOST'] Returns the Host name from where the user is viewing the current page. $_SERVER['REMOTE_PORT']


1 Answers

$ip = trim(shell_exec("dig +short myip.opendns.com @resolver1.opendns.com"));

dd("Public IP: ".$ip); //"Public IP: 24.62.137.161"
like image 199
code-8 Avatar answered Sep 22 '22 03:09

code-8