How to get a Client IP address in Laravel - TechvBlogs

How to get a Client IP address in Laravel

In this article, We will share with you how to get an IP address in your Laravel application with several way examples.


Suresh Ramani - Author - TechvBlogs
Suresh Ramani
 

6 months ago

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

If you want to manage your VPS / VM Server without touching the command line go and  Checkout this linkServerAvatar allows you to quickly set up WordPress or Custom PHP websites on VPS / VM in a  matter of minutes.  You can host multiple websites on a single VPS / VM, configure SSL certificates, and monitor the health of your server without ever touching the command line interface.

Comments (0)

ServerAvatar
Multiple sites on a single VPS/VM/Server Deploy PHP sites on cloud in minutes, simple as that!
ServerAvatar
Generate Free SSL Certificate - SSLForWeb

Generate Free SSL Certificate

  • 90-Day Certificates
  • SSL Monitoring
  • Wildcard Certificates
  • Multiple Domains
  • Certificate Management
  • Expiration Reminders

Comment


Note: All Input Fields are required.