View Single Post
Old 08-13-2015, 05:40 AM  
AdultKing
Raise Your Weapon
 
AdultKing's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
Quote:
Originally Posted by RummyBoy View Post
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;
?>
AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote