Extract Geolocation by IP Address in PHP

<?php
    		class Request
            {
            
                public function getIpAddress()
                {
                    $ipAddress = '';
                    if (! empty($_SERVER['HTTP_CLIENT_IP']) && $this->isValidIpAddress($_SERVER['HTTP_CLIENT_IP'])) {
                        // check for shared ISP IP
                        $ipAddress = $_SERVER['HTTP_CLIENT_IP'];
                    } else if (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                        // check for IPs passing through proxy servers
                        // check if multiple IP addresses are set and take the first one
                        $ipAddressList = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                        foreach ($ipAddressList as $ip) {
                            if ($this->isValidIpAddress($ip)) {
                                $ipAddress = $ip;
                                break;
                            }
                        }
                    } else if (! empty($_SERVER['HTTP_X_FORWARDED']) && $this->isValidIpAddress($_SERVER['HTTP_X_FORWARDED'])) {
                        $ipAddress = $_SERVER['HTTP_X_FORWARDED'];
                    } else if (! empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->isValidIpAddress($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
                        $ipAddress = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
                    } else if (! empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->isValidIpAddress($_SERVER['HTTP_FORWARDED_FOR'])) {
                        $ipAddress = $_SERVER['HTTP_FORWARDED_FOR'];
                    } else if (! empty($_SERVER['HTTP_FORWARDED']) && $this->isValidIpAddress($_SERVER['HTTP_FORWARDED'])) {
                        $ipAddress = $_SERVER['HTTP_FORWARDED'];
                    } else if (! empty($_SERVER['REMOTE_ADDR']) && $this->isValidIpAddress($_SERVER['REMOTE_ADDR'])) {
                        $ipAddress = $_SERVER['REMOTE_ADDR'];
                    }
                    return $ipAddress;
                }
            
                public function isValidIpAddress($ip)
                {
                    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
                        return false;
                    }
                    return true;
                }
            
                public function getLocation($ip)
                {
                    $ch = curl_init('http://ipwhois.app/json/' . $ip);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    $json = curl_exec($ch);
                    curl_close($ch);
                    // Decode JSON response
                    $ipWhoIsResponse = json_decode($json, true);
                    // Country code output, field "country_code"
                    return $ipWhoIsResponse;
                }
            }
    
            $requestModel = new Request();
            $ip = $requestModel->getIpAddress();
            $isValidIpAddress = $requestModel->isValidIpAddress($ip);
            ?>
            
            <link href="assets/css/stylee.css" type="text/css" rel="stylesheet" />
            
            	<div class="txt-heading">Get Geo Location by the IP address</div>
            			<?php
            if ($isValidIpAddress == "") {
                echo "<div class='error'>Invalid IP address $ip</div>";
            } else {
                $geoLocationData = $requestModel->getLocation($ip);
                print "<PRE>";
                print_r($geoLocationData);
                ?>
            	<div id="location">
            		<div class="geo-location-detail">
            
            			<div class="row">
            				<div class="form-label">
            					Country Name: <?php  echo $geoLocationData['country'];?>
            				</div>
            			</div>
            			<div class="row">
            				<div class="form-label">
            					Country Code: <?php   echo $geoLocationData['country_code'];?>
            				</div>
            			</div>
            			<div class="row">
            				<div class="form-label">
            					Ip Address: <?php  echo $geoLocationData['ip'];?>
            				</div>
            			</div>
            		</div>
            	</div>
            <?php }?>
Get Geo Location by the IP address
Array
(
 [ip] => 3.236.225.157
 [success] => 1
 [type] => IPv4
 [continent] => North America
 [continent_code] => NA
 [country] => United States
 [country_code] => US
 [country_flag] => https://cdn.ipwhois.io/flags/us.svg
 [country_capital] => Washington D.C.
 [country_phone] => +1
 [country_neighbours] => CA,MX
 [region] => Virginia
 [city] => Ashburn
 [latitude] => 39.0437567
 [longitude] => -77.4874416
 [asn] => AS14618
 [org] => Amazon Data Services NoVa
 [isp] => Amazon.com, Inc.
 [timezone] => America/New_York
 [timezone_name] => EDT
 [timezone_dstOffset] => 3600
 [timezone_gmtOffset] => -14400
 [timezone_gmt] => -04:00
 [currency] => US Dollar
 [currency_code] => USD
 [currency_symbol] => $
 [currency_rates] => 1
 [currency_plural] => US dollars
)
Country Name: United States
Country Code: US
Ip Address: 3.236.225.157