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.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 08-13-2015, 05:35 AM   #1
RummyBoy
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:
<?php
$geo
=geoip_record_by_name ($_SERVER['REMOTE_ADDR']);
echo 
$geo['city'];
if (
$geo == "") {
   
$geo['city'] = "Your City";
?>
RummyBoy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-13-2015, 05:40 AM   #2
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
Old 08-13-2015, 06:06 AM   #3
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Do
Code:
<? print_r($_SERVER); ?>
If you don't see your country listed, it means the module or database for it is not properly configured.

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.
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-13-2015, 06:16 AM   #4
AdultKing
Raise Your Weapon
 
AdultKing's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
Quote:
Originally Posted by k0nr4d View Post
Do
Code:
<? print_r($_SERVER); ?>
If you don't see your country listed, it means the module or database for it is not properly configured.

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.
But even then

Code:
if ($geo == "") {
   $geo['city'] = "Your City";
?>
won't work will it ?

I'm not on my dev machine so I can't try it.
AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-13-2015, 06:48 AM   #5
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Quote:
Originally Posted by AdultKing View Post
But even then

Code:
if ($geo == "") {
   $geo['city'] = "Your City";
?>
won't work will it ?

I'm not on my dev machine so I can't try it.
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.
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-13-2015, 07:01 AM   #6
AdultKing
Raise Your Weapon
 
AdultKing's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
Quote:
Originally Posted by k0nr4d View Post
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.
Im pedantic
AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-13-2015, 08:06 PM   #7
RummyBoy
Confirmed User
 
Join Date: Dec 2009
Posts: 2,157
any clues people?
RummyBoy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 01:07 AM   #8
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Quote:
Originally Posted by RummyBoy View Post
any clues people?
IF your geoip module is properly configured...

Code:
<?php
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
if(!$geo['city']) {
   $geo['city'] = "Your City";
}
?>
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 04:25 AM   #9
RummyBoy
Confirmed User
 
Join Date: Dec 2009
Posts: 2,157
Well my code shows me a city.... your code doesnt work for me at all.
Doesn't show any city.

Quote:
Originally Posted by k0nr4d View Post
IF your geoip module is properly configured...

Code:
<?php
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
if(!$geo['city']) {
   $geo['city'] = "Your City";
}
?>
RummyBoy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 05:24 AM   #10
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
Well my code shows me a city.... your code doesnt work for me at all.
Doesn't show any city.
Can you please post the output from the following code.

Code:
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
echo  $geo['city'];
and

Code:
$geo = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
print_r($geo);
AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 07:25 AM   #11
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,063
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
Old 08-14-2015, 07:51 AM   #12
daddy_fu
Registered User
 
daddy_fu's Avatar
 
Industry Role:
Join Date: Aug 2015
Location: NYC
Posts: 15
Quote:
Originally Posted by sarettah View Post
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.
For a second there I was ready to jump in and see if I could help, but after RummyBoy's last reply I can see it's a lost cause.
__________________
Lead Developer - Nudeflix
daddy_fu is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 08:00 AM   #13
AdultKing
Raise Your Weapon
 
AdultKing's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
Quote:
Originally Posted by sarettah View Post
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.
Yeah I said that, read up where I said I was pedantic.

I think it was lost on him.
AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 08:02 AM   #14
RummyBoy
Confirmed User
 
Join Date: Dec 2009
Posts: 2,157
Quote:
Originally Posted by sarettah View Post
So, without meaning anything derogatory here, let's take this to kindergarten level.
Yep, kindergarten level was needed in fact. I should have told you guys im clueless.

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.
RummyBoy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 08:04 AM   #15
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
Yep, kindergarten level was needed in fact. I should have told you guys im clueless.
Nah, you're not. You were smart enough to ask the question and the only dumb question is one you don't ask.

AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-14-2015, 09:30 AM   #16
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,063
Quote:
Originally Posted by AdultKing View Post
Yeah I said that, read up where I said I was pedantic.
Ooops, I read that as "Im pathetic". Sorry about that. My bad ;p

Quote:
Originally Posted by RummyBoy View Post
Yep, kindergarten level was needed in fact. I should have told you guys im clueless.
Nothing wrong with Kindergarten code

Quote:
Originally Posted by AdultKing View Post
Nah, you're not. You were smart enough to ask the question and the only dumb question is one you don't ask.

+1

.
__________________
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
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
geo, city, code, module, enabled, wrong, simple, expert, intended, pull, determine, database
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.