I have function that basically returns visitor's country code and another that gets the currency. While running XAMPP on Windows, the return values of the function gets echoed like expected. On Linux (eOS Loki), I've manually installed the LAMPP stack (not running XAMPP), this time PHP won't echo the return values of the functions. The page would stop loading, with no errors.
page stops loading immediately
NB: nhazi.dev is localhost
Country code function
function get_ipinfo( $option )
{
$url = "http://ipinfo.io/" . $_SERVER['REMOTE_ADDR'] . "/json";
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1') // I develop offline most times.
{
$url = "http://nhazi.dev/php_curl/json"; //Offline Debugging
}
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true
)
);
$data = json_decode( curl_exec($ch) ); // decodes json response
curl_close($ch);
// Return value based on option
if(! $option)
return $data;
if($option == 'ip')
return $data->ip;
if($option == 'city')
return $data->city;
if($option == 'region')
return $data->region;
if($option == 'country')
return $data->country;
if($option == 'location')
return $data->loc;
if($option == 'org')
return $data->org;
}
Currency code function
function get_currency( $countrycode )
{
$url = "http://country.io/currency.json";
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
{
$url = "http://nhazi.dev/php_curl/currency"; //Offline Debugging
}
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
)
);
$currency = json_decode(curl_exec($ch));
// print_r($currency); // Debugging
curl_close($ch);
return $currency->$countrycode;
}
Function Implementation
<p>
<?php echo get_currency( get_ipinfo('country') ); ?>
</p>