How To Get Client IP Address In Laravel 9

Websolutionstuff | Oct-26-2022 | Categories : Laravel PHP

In this article, we will see how to get a client's IP address in laravel 9. Many times you need a user IP address in the laravel application. So, here we will learn laravel 9 to get client IP address. An IP (Internet Protocol) address is a unique address that identifies a device on the internet or a local network. An Internet Protocol address (IP address) is a numerical label such as 192.0.2.1 that is connected to a computer network that uses the Internet Protocol for communication.

How To Get Client IP Address In Laravel 9?

You can get an IP address using Request IP, Request getClientIp, and the request helper function.

we will get an IP address using the request. In laravel include use Illuminate\Http\Request; controller. the Request method provides the ip() method.

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

dd($clientIP);

 

public function index(Request $request)
{
    dd($request->ip());
}

 

$clientIP = \Request::ip();

dd($clientIP)

This method can read the client IP address from the "X-Forwarded-For" header. getClientIp() method returns the client IP address.

$clientIP = \Request::getClientIp(true);

dd($clientIP);

 


You might also like:

Recommended Post
Featured Post
Laravel 10 Scout Search and Algolia Example
Laravel 10 Scout Search and Al...

Hey everyone! Ever wished your Laravel application could deliver lightning-fast search results? Well, I've got great...

Read More

Feb-21-2024

How To Validate 10 Digit Mobile Number Using Regular Expression
How To Validate 10 Digit Mobil...

In This small tutorial, I will explain to you how to validate a 10-digit mobile number using regular expressions in...

Read More

Jun-15-2020

How to Create Custom Facade in Laravel 10
How to Create Custom Facade in...

Laravel, one of the most popular PHP frameworks, provides a powerful feature known as facades. Facades allow you to acce...

Read More

Sep-22-2023

How to Create New Component in Angular 17 using Command
How to Create New Component in...

Welcome to this comprehensive tutorial where I'll guide you through the process of creating a new component in Angul...

Read More

Mar-22-2024