![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Dec 2009
Posts: 2,157
|
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:
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 | |
Raise Your Weapon
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
|
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 # 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; ?> |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
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.
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 | |
Raise Your Weapon
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
|
Quote:
Code:
if ($geo == "") { $geo['city'] = "Your City"; ?> I'm not on my dev machine so I can't try it. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
It's not "correct" but php is very forgiving, it won't error out and just in that isolated piece of code will work. He should be comparing to $geo['city'] though.
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Raise Your Weapon
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Dec 2009
Posts: 2,157
|
any clues people?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
IF your geoip module is properly configured...
Code:
<?php $geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']); if(!$geo['city']) { $geo['city'] = "Your City"; } ?>
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Join Date: Dec 2009
Posts: 2,157
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
Raise Your Weapon
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
|
Quote:
Code:
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']); echo $geo['city']; Code:
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']); print_r($geo); |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,063
|
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. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Raise Your Weapon
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
Confirmed User
Join Date: Dec 2009
Posts: 2,157
|
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. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Raise Your Weapon
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 | ||
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,063
|
Ooops, I read that as "Im pathetic". Sorry about that. My bad ;p
Quote:
![]() Quote:
![]() .
__________________
All cookies cleared! |
||
![]() |
![]() ![]() ![]() ![]() ![]() |