Quote:
Originally Posted by RummyBoy
Its a simple GEO IP which is intended to pull the City name from the database according to IP but if it cannot determine the City name, it should show just "Your City". GEO IP module is enabled but this code isn't working.
Can someone please show me what I'm doing wrong here?
PHP Code:
<?php $geo=geoip_record_by_name ($_SERVER['REMOTE_ADDR']); echo $geo['city']; if ($geo == "") { $geo['city'] = "Your City"; ?>
|
You are trying to compare an array as a string on line 4.
You need to address the key in the array to get the string.
Here's a sample from PHP.NET
Code:
<?php
# Collect a specific users GEOIP info
$info = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
print_r ($info);
# To get the info from one specific field
$country = $info['country_name'];
echo $country;
# To combine information from the array into a string
$info = implode("/", $info);
echo $info;
?>