I am trying to show content based on user location. For example, show if outside of the country, Australia.
I have been using the documentation from this link: http://www.geoplugin.com/webservices/php
This is the code I have been using. It will always show the echo even when I change the location.
<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
// If we wanted to change the base currency, we would uncomment the following line
// $geoplugin->currency = 'EUR';
$geoplugin->locate();
echo "Geolocation results for {$geoplugin->ip}: <br />
".
"Country Name: {$geoplugin->countryName} <br />
".
"Country Code: {$geoplugin->countryCode} <br />
";
if ( $geoplugin->countryName != "Australia" ) {
//our visitor is not using the same currency as the base currency
echo "Show International Popup";
}
?>
Cheers
Personally, If I was you, I'd go via the countryCode
instead of the countryName
. It's more "containable" in a sense.
if($geoplugin->countryCode !== "AU") {
// load your selector
}
On another note, what does your countryName
/countryCode
show? Is anything present in either of the variables?
Make sure you have error reporting on, encase your calls are failing:
ini_set('display_errors', 1);
display_errors(-1); // or use E_ALL