How to Get IP Address in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Today our leading topic is laravel get client ip address. I would like to share with you laravel get ip address. I would like to share with you how to get ip address in laravel. it's simple example of how to get client ip address in laravel. you will do the following things for how to get browser ip address in laravel.

An IP address (Internet Protocol address) is a numerical label assigned to every device connected to a computer network that uses the Internet Protocol for communication. It serves as a unique identifier for devices on the network and allows them to communicate with each other. An IP address consists of a series of numbers separated by periods, such as "192.168.0.1". There are two main types of IP addresses: IPv4 (32-bit) and IPv6 (128-bit). IPv4 is the most commonly used and is composed of four numbers ranging from 0 to 255, while IPv6 uses hexadecimal notation and has a significantly larger address space to accommodate the growing number of devices on the internet.

Here, i will give 4 ways to getting client IP Address in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 application.

Example 1:

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

dd($clientIP);

Example 2:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index(Request $request)

{

$clientIP = $request->ip();

dd($clientIP);

}

}

Example 3:

$clientIP = \Request::ip();

dd($clientIP);

Example 4:

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

dd($clientIP);

i hope it can help you...

Tags :
Shares