I wish to provide location based content i.e I want to allow only users located in Arizona to view the video displayed on my page. However users outside Arizona are also able to view the page.I am using http://freegeoip.net web service to determine users locations from their IP addresses.
This is the code embedded in the webpage
<?php require_once("geofilter.php"); ?>
<?php
if (getRegion()=="Arizona")
//if (getCity()=="Tempe" || getCity()=="Chandler")
{
?>
<iframe src = 'videourl' height='415' width='615' align='top' scrolling='no' frameborder='0'></iframe>
<?php
} else
{
?>
<h1 style="color:#F00">This page is not available in your region: <?php echo (getCity().", ".getRegion());?></h1>
<?php }?>
this is the code for geofilter.php
<?php
function getCountry()
{
$pageContent = file_get_contents('http://freegeoip.net/json/');
$parsedJsonCountry = json_decode($pageContent);
return htmlspecialchars($parsedJsonCountry->country_name);
}
function getRegion()
{
$pageContent = file_get_contents('http://freegeoip.net/json/');
$parsedJsonRegion = json_decode($pageContent);
return htmlspecialchars($parsedJsonRegion->region_name);
}
function getCity()
{
$pageContent = file_get_contents('http://freegeoip.net/json/');
$parsedJsonCity = json_decode($pageContent);
return htmlspecialchars($parsedJsonCity->city);
}
function getZipCode()
{
$pageContent = file_get_contents('http://freegeoip.net/json/');
$parsedJsonZip = json_decode($pageContent);
return htmlspecialchars($parsedJsonZip->zipcode);
}
function getIpAddress()
{
$pageContent = file_get_contents('http://freegeoip.net/json/');
$parsedJsonIp = json_decode($pageContent);
return htmlspecialchars($parsedJsonIp->ip);
}
?>