logo

How can get client IP Address in Drupal 8

24
March

How can get client IP Address in Drupal 8
By: Anonymous | Published On: Wed, 03/24/2021 - 22:12

I want to know IP Address of my website so can who is visiting or I want to location where is website visited using IP address.

Soln,

Add this code at top like other header

use Symfony\Component\HttpFoundation;

Use this code to get IP Address

\Drupal::request()->getClientIp()

Need Help ?