View Single Post
Old 08-14-2015, 07:25 AM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,067
Quote:
Originally Posted by RummyBoy View Post
Well my code shows me a city.... your code doesnt work for me at all.
Doesn't show any city.
That is because K0nrad did NOT include an echo in there. I think he assumed you knew to echo the output but after reading the thread I don't know that you do. So, without meaning anything derogatory here, let's take this to kindergarten level.

Your code:

$geo=geoip_record_by_name ($_SERVER['REMOTE_ADDR']);
echo $geo['city'];
if ($geo == "") {
$geo['city'] = "Your City";
}

You are echoing the city before you test to see if city is filled. So you see whatever city the geo returned. You might also see nothing come back if the city is blank. You will NEVER see "Your City" come back because you are pushing the output before the if statement. Does that make sense to you?

Also K0nrad, AK and I think you have a mistake in the if statement. You are checking against geo (if geo="") not against geo['city']. You should be comparing against city.

K0nrad fixed the if statement for you but he removed the echo (which was in the wrong place). So let's try K0nrads code with an echo added:

$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
if(!$geo['city']) {
$geo['city'] = "Your City";
}
echo $geo['city'];

That should show the city if geo_ip returned a city and should show "Your City" if geo_ip['city'] comes back null or empty.

See if that works for you or not.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote