PHP 7 Script to Get Website Visitor Location,IP Address,Country and City Using Freegeoip and ipstack API Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

Welcome folks today in this blog post we will be getting the website visitor location ip address,country and city in php 7 using freegeoip and ipstackapi api All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make a index.php file and copy paste the following code

 

 

index.php

 

 

 

<?php
$ip = $_SERVER['REMOTE_ADDR']; 
$freegeoipjson = file_get_contents("http://freegeoip.net/json/". $ip ."");

$jsondata = json_decode($freegeoipjson);
$countryfromip = $jsondata->country_name;
$cityfromip = $jsondata->city;

echo "City: ". $cityfromip ."";
echo "<br/>";
echo "Country: ". $countryfromip ."";
?>

 

Leave a Reply