Client IP address in Laravel: How to Retrieve User IP Easily - Techvblogs

Client IP address in Laravel: How to Retrieve User IP Easily

Learn how to get the Client IP address in Laravel to track visitors and enhance security in your web applications.


Suresh Ramani - Author - Techvblogs
Suresh Ramani
 

3 days ago

TechvBlogs - Google News

What is an IP Address?

An Internet Protocol(IP) address also known as a logical address is given by the internet service provider(ISP) which uniquely identifies a system over the network. IP address keeps on changing from time to time.

How to get a Client IP address 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.

$clientIP = request()->ip();
dd($clientIP);

Read Also: What's New in Laravel 9: New Features of Laravel 9 

public function index(Request $request){
  dd($request->ip());
}
$clientIP = \Request::ip();
dd($clientIP);
$clientIP = \Request::getClientIp(true);
dd($clientIP);

 Thank you for reading this blog.

Read Also: Laravel 9 Authentication Tutorial

Comments (0)

Comment


Note: All Input Fields are required.