1The simplest way to collect the Client/Visitor IP address using PHP is the REMOTE_ADDR.
2Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.
3
4Get the IP address of the website
5<?php
6echo 'User IP Address : '. $_SERVER['REMOTE_ADDR'];
7?>
8
9/*
10I Hope it will help you.
11Namaste
12Stay Home Stay Safe
13*/
1//You can use an api:
2//Link to documentation: https://ip-get-geolocation.com/documentation/
3
4$LocationArray = json_decode( file_get_contents('http://ip-get-geolocation.com/api/json/35.188.125.133'), true);
5
6echo $LocationArray['country'];
7echo $LocationArray['city'];
8echo $LocationArray['region'];
9echo $LocationArray['timezone'];
1// Function to get the client IP address
2function get_client_ip() {
3 $ipaddress = '';
4 if (getenv('HTTP_CLIENT_IP'))
5 $ipaddress = getenv('HTTP_CLIENT_IP');
6 else if(getenv('HTTP_X_FORWARDED_FOR'))
7 $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
8 else if(getenv('HTTP_X_FORWARDED'))
9 $ipaddress = getenv('HTTP_X_FORWARDED');
10 else if(getenv('HTTP_FORWARDED_FOR'))
11 $ipaddress = getenv('HTTP_FORWARDED_FOR');
12 else if(getenv('HTTP_FORWARDED'))
13 $ipaddress = getenv('HTTP_FORWARDED');
14 else if(getenv('REMOTE_ADDR'))
15 $ipaddress = getenv('REMOTE_ADDR');
16 else
17 $ipaddress = 'UNKNOWN';
18 return $ipaddress;
19}