How to get client IP address in Laravel 5

0 votes
I am trying to get the client's IP address in Laravel.

It is easy to get a client's IP in PHP by using $_SERVER["REMOTE_ADDR"]. It is working fine in core PHP, but when I use the same thing in Laravel, it returns the server IP instead of the visitor's IP.
Sep 11, 2020 in Laravel by kartik
• 37,490 points
125 views

1 answer to this question.

0 votes

Hello @kartik,

Use request()->ip().

Since Laravel 5 it's advised/good practice to use the global functions like:

response()->json($v);
view('path.to.blade');
redirect();
route();
cookie();

You can also refer this:https://www.edureka.co/community/65056/how-to-get-user-s-ip-address-in-laravel?show=80036#c80036

Hope it helps!!
Thank You!!

answered Sep 11, 2020 by Niroj
• 82,560 points

Related Questions In Laravel

0 votes
1 answer

How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

Hey, In order to identify the type of ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,560 points
211 views
0 votes
1 answer

How to get distinct values for non-key column fields in Laravel?

Hello @kartik In eloquent you can use this $users ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,560 points
8,460 views
0 votes
1 answer

How to get a list of registered route paths in Laravel?

Hello, Route::getRoutes() returns a RouteCollection. On each element, you can ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,560 points
613 views
0 votes
1 answer

How to get all pending jobs in laravel queue on redis?

Hello @kartik, Here is the way I do ...READ MORE

answered Apr 6, 2020 in Laravel by Niroj
• 82,560 points
2,733 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,560 points
5,565 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,560 points
642 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,560 points
491 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,560 points
6,143 views
0 votes
1 answer

How to access client ip address in Laravel 5?

Hello @kartik, You can use this type of ...READ MORE

answered Nov 11, 2020 in Laravel by Niroj
• 82,560 points
913 views
0 votes
5 answers

How to get user's IP address in Laravel?

Looking at the Laravel API: Request::ip(); Internally, it uses the getClientIps the ...READ MORE

answered Dec 15, 2020 in Laravel by Roshni
• 10,420 points
17,337 views