![]() |
GEO IP Code Expert Needed
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:
|
Quote:
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 |
Do
Code:
<? print_r($_SERVER); ?> I don't remember the exact variable, but you should be able to access the country with $_SERVER['GEOIP_COUNTRY_NAME'] or something like that - it will be listed in that $_SERVER dump. |
Quote:
Code:
if ($geo == "") { I'm not on my dev machine so I can't try it. |
Quote:
|
Quote:
|
any clues people?
|
Quote:
Code:
<?php |
Well my code shows me a city.... your code doesnt work for me at all.
Doesn't show any city. Quote:
|
Quote:
Code:
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']); Code:
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']); |
Quote:
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. . |
Quote:
|
Quote:
I think it was lost on him. |
Quote:
I haven't been able to test the default "Your City" but this version does actually seem to work. Thanks for all your help people. |
Quote:
:thumbsup |
Quote:
Quote:
Quote:
. |
All times are GMT -7. The time now is 09:21 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123