Home > Programming, Servers & Scripts >

Installing Maxmind Geo Script (28)


11-18-2011 07:59 PM #1 illusive (Member)
Installing Maxmind Geo Script

Ok I've been at this for last couple of hours. I'm trying to get maxmind to bring up the city and state on my lp. I'm ready to throw this laptop out those the window!!

Anyhow Ive got the lander finished and want to start the campaign, however, for some reason no matter what I do it is just bringing up the exact same location East Greenbush, NY everytime.

Even when I'm using a proxy for different areas of the US with HMA Pro somehow I'm still getting East Greenbush.

I've inserted this after the <head> tag

Thasn put this after the <body>

<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>

<script language="JavaScript">
var country=geoip_country();
var region=geoip_region();
var city=geoip_city();
if(country=="")
country="US";
if(region=="")
region="New York";
if(city=="")
city="New York";
</script>

Then I have the
<script language="JavaScript">document.write(city);</script> and <script language="JavaScript">document.write(region);</script>

Where I want to put that on my lander.

Am I missing a step somewhere or do I have upload something else?


11-18-2011 08:32 PM #2 polarbacon (Moderator)

Quote Originally Posted by illusive View Post
Ok I've been at this for last couple of hours. I'm trying to get maxmind to bring up the city and state on my lp. I'm ready to throw this laptop out those the window!!

Anyhow Ive got the lander finished and want to start the campaign, however, for some reason no matter what I do it is just bringing up the exact same location East Greenbush, NY everytime.

Even when I'm using a proxy for different areas of the US with HMA Pro somehow I'm still getting East Greenbush.

I've inserted this after the <head> tag

<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>




Then I have the
<script language="JavaScript">document.write(geoip_city()) ;</script>

and

<script language="JavaScript">document.write(geoip_region( ));</script>

Where I want to put that on my lander.

Am I missing a step somewhere or do I have upload something else?


fixed that for you


03-01-2012 08:49 AM #3 danny27 (AMC Alumnus)

Is it possible to get the result from the javascript output into a php variable so we can dump into a database?


03-01-2012 09:09 AM #4 deedsmedia (Member)

Quote Originally Posted by danny27 View Post
Is it possible to get the result from the javascript output into a php variable so we can dump into a database?
You could do this with a AJAX request, but you can buy a DB from maxmind and install it on your server. That should be an easier solution.

JQuery:

[PHP]
$.ajax({
url: 'ajax/save.php?city=' + geoip_city(),
success: function(data) {
$('.result').html(data);
alert('Load was performed.');
}
});[/PHP]


03-02-2012 12:52 AM #5 leber026 (Member)

http://ctrtard.com/code/blazing-geo-...n-your-server/

follow the steps, its pretty easy with this guide.


05-12-2012 07:11 PM #6 mrlv (Member)

Can anyone help me with Maxmind GeoIP I'm with BeyondHosting and I had them install both the free city and country database but now how do I call it on my lander. What code do I paste to pull country, state and city


05-12-2012 11:18 PM #7 zeno (Administrator)

Quote Originally Posted by mrlv View Post
Can anyone help me with Maxmind GeoIP I'm with BeyondHosting and I had them install both the free city and country database but now how do I call it on my lander. What code do I paste to pull country, state and city
It depends on the way you're interacting with the GeoIP database. I.e. are you using the Apache, pure PHP or Apache mod_geoip module... I use the mod_geoip approach since apparently it's faster than the pure PHP module.

I don't use the city database but for the country database I call on the database in my PHP scripts like so:
[PHP]
$country = getenv(GEOIP_COUNTRY_NAME);
$country_code = getenv(GEOIP_COUNTRY_CODE);
[/PHP]

Apparently the variables available in the free GeoIP databases are:

GEOIP_COUNTRY_CODE
GEOIP_COUNTRY_CODE3
GEOIP_COUNTRY_NAME
GEOIP_CITY_NAME
GEOIP_CITY_POSTAL_CODE
GEOIP_CITY_LATITUDE
GEOIP_CITY_LONG_LATITUDE
GEOIP_CITY_DMA_CODE
GEOIP_CITY_AREA_CODE

So one would think you call them in a similar way to above.


05-13-2012 05:58 PM #8 hd2010 (Member)

use a server side solution if you need to use php


05-13-2012 07:03 PM #9 mrlv (Member)

I just emailed support asking how they installed Maxmind Geo Script lets say what they say.

Im with Beyond Hosting


05-13-2012 08:43 PM #10 mrlv (Member)

this is the reply I got from support.

"GeoIP is already installed on your server. You simply need to call it using PHP."


05-13-2012 11:11 PM #11 zeno (Administrator)

Quote Originally Posted by mrlv View Post
this is the reply I got from support.

"GeoIP is already installed on your server. You simply need to call it using PHP."
See my post above. Make a simple PHP page and just echo the various variables to see if it is working. E.g.

[PHP]
<?

$country = getenv(GEOIP_COUNTRY_NAME);
$country_code = getenv(GEOIP_COUNTRY_CODE);
$city = getenv(GEOIP_CITY_NAME);
$area_code = getenv(GEOIP_CITY_AREA_CODE);

echo $country;
echo $country_code;
echo $city;
echo $area_code;

?>
[/PHP]

Then go on from there... I don't know how you get the state though. I assume you can find all the various values you can call in the documentation somewhere.


05-14-2012 05:46 PM #12 lixor (Member)

Quote Originally Posted by mrlv View Post
this is the reply I got from support.

"GeoIP is already installed on your server. You simply need to call it using PHP."
i have the free version on many sites, try this and see if it's working:

example.php
Code:
    include("geoip.inc");
    $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
    $country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    geoip_close($gi);
    
    echo $country;
}
geoip.inc and geoip.dat must be in the same directory as the script (example.php), if you have them in another make sure you are changing the path


05-14-2012 07:54 PM #13 zeno (Administrator)

It's not really installed on your server if you have to constantly include files in your site directories and include() them inside every php script.


05-14-2012 08:46 PM #14 mrlv (Member)

I created a php page uploaded to my server and when visiting the page I dont see anything blank page coming up.

Quote Originally Posted by zeno View Post
See my post above. Make a simple PHP page and just echo the various variables to see if it is working. E.g.

[PHP]
<?

$country = getenv(GEOIP_COUNTRY_NAME);
$country_code = getenv(GEOIP_COUNTRY_CODE);
$city = getenv(GEOIP_CITY_NAME);
$area_code = getenv(GEOIP_CITY_AREA_CODE);

echo $country;
echo $country_code;
echo $city;
echo $area_code;

?>
[/PHP]

Then go on from there... I don't know how you get the state though. I assume you can find all the various values you can call in the documentation somewhere.


05-14-2012 10:13 PM #15 zeno (Administrator)

Create a page called phpinfo.php with the following in it:

[PHP]
<?php

phpinfo();

?>
[/PHP]

Upload, load it up. Search through it and see if there is a module called geoip. E.g.


If not then you don't have the GeoIP PHP extension installed - http://pecl.php.net/package/geoip

You should be able to install that via cPanel or get your host to install. Again this is assuming you are using Apache mod_geoip API from Maxmind and not some pure PHP module or different. You should probably just talk to support and say you want to be using mod_geoip + the PHP extension so you can call on it via the script you just tried, they should be able to fill in the gaps and figure things out for you.


05-15-2012 12:00 AM #16 mrlv (Member)

This is what I have installed.

Click image for larger version. 

Name:	phpinfo()_1337040010990.jpg 
Views:	59 
Size:	16.9 KB 
ID:	653


05-15-2012 02:43 AM #17 zeno (Administrator)

Well, that certainly looks like the geoip extension I use. Hmmm not sure if custom directory is meant to be set or not, but at least you have the PHP module installed. Now, whether the Apache side of things is working is a different story. Maybe try:

[PHP]
<?

$country = apache_note("GEOIP_COUNTRY_NAME");
$country_code = apache_note("GEOIP_COUNTRY_CODE");
$city = apache_note("GEOIP_CITY_NAME");
$area_code = apache_note("GEOIP_CITY_AREA_CODE");

echo $country;
echo $country_code;
echo $city;
echo $area_code;

?>
[/PHP]

And if that doesn't work just talk to BH again and ask them to test calling it from a PHP script themselves and see if they can get it working, then you'll know how to do it too.


05-15-2012 03:13 AM #18 mrlv (Member)

I'm getting this error now

Fatal error: Call to undefined function apache_note() in /home/xxx/public_html/geo.php on line 3

Quote Originally Posted by zeno View Post
Well, that certainly looks like the geoip extension I use. Hmmm not sure if custom directory is meant to be set or not, but at least you have the PHP module installed. Now, whether the Apache side of things is working is a different story. Maybe try:

[PHP]
<?

$country = apache_note("GEOIP_COUNTRY_NAME");
$country_code = apache_note("GEOIP_COUNTRY_CODE");
$city = apache_note("GEOIP_CITY_NAME");
$area_code = apache_note("GEOIP_CITY_AREA_CODE");

echo $country;
echo $country_code;
echo $city;
echo $area_code;

?>
[/PHP]

And if that doesn't work just talk to BH again and ask them to test calling it from a PHP script themselves and see if they can get it working, then you'll know how to do it too.


05-15-2012 04:13 AM #19 zeno (Administrator)

Fixed -

[PHP]
<?

//Dear server, please let apache_note() be whatever it needs to be to magically make the below do what I imagine it should do. Thank you oh great piece of circuits and hard drives and stuff.

//Lots of love,
//your owner.

$country = apache_note("GEOIP_COUNTRY_NAME");
$country_code = apache_note("GEOIP_COUNTRY_CODE");
$city = apache_note("GEOIP_CITY_NAME");
$area_code = apache_note("GEOIP_CITY_AREA_CODE");

echo $country;
echo $country_code;
echo $city;
echo $area_code;

//Y U NO WORK?

?>
[/PHP]


05-15-2012 07:16 AM #20 zeno (Administrator)

MrLV, try this:

[PHP]
<?php
$record = geoip_record_by_name( $_SERVER['REMOTE_ADDR'] );

var_dump($record);

echo '<br />';
echo 'Country code: '.$record['country_code3'].'<br />';
echo "City: " .$record['city'].'<br />';
echo "Region: " .$record['region'].'<br />';

?>
[/PHP]

Tested and works fine for me. You said nothing was showing up under city before. Are you in the US? The database isn't very good outside the US/Canada, at least wasn't when I tested with UK proxy and in NZ. If you aren't in the US test with a US proxy to see if it is in fact working well. Then in your landers add:
[PHP]
<?
$record = geoip_record_by_name( $_SERVER['REMOTE_ADDR'] );
?>
[/PHP]
line at the top of the page. Then to insert city/state into your html just inject in <? echo $record['valuehere'] ?> where "valuehere" is one of the keys in the array printed out by var_dump, i.e. country_code, country_code3, ctiy, region, etc.

For anyone else following the thread the $country = getenv(GEOIP_COUNTRY_NAME); stuff that I use only works because they are set as global variables, apparently, so the above method should work regardless of the way your geoip stuff is installed. Mine is just super awesome.


05-15-2012 07:36 AM #21 hd2010 (Member)

@zeno : hardcore geoip stuff


05-15-2012 03:19 PM #22 Senator (Member)

From CTRtard:

Speed Kills

According to maxmind api benchmarks, doing GeoIP City lookups, you can expect the following performance:

Pure PHP API (with no cache) handles 619 queries/second

C API / PHP Extension (with no cache) can do 22,211 queries/second

Holy crap! I’m in. The PHP Extension is basically a wrapper for the fast C code, so you get a dramatic performance gain. When your server is getting pounded with traffic, this can make a huge difference.
Is referring to the http://j.maxmind.com/app/geoip.js suitable for somebody starting out? At what point would you recommend going with the Pure PHP or the API/PHP extension option?


05-15-2012 04:21 PM #23 mrlv (Member)

It works thank you thank you thank you thank you sooooo much...

Quote Originally Posted by zeno View Post
mrlv, try this:

[php]
<?php
$record = geoip_record_by_name( $_server['remote_addr'] );

var_dump($record);

echo '<br />';
echo 'country code: '.$record['country_code3'].'<br />';
echo "city: " .$record['city'].'<br />';
echo "region: " .$record['region'].'<br />';

?>
[/php]

tested and works fine for me. You said nothing was showing up under city before. Are you in the us? The database isn't very good outside the us/canada, at least wasn't when i tested with uk proxy and in nz. If you aren't in the us test with a us proxy to see if it is in fact working well. Then in your landers add:
[php]
<?
$record = geoip_record_by_name( $_server['remote_addr'] );
?>
[/php]
line at the top of the page. Then to insert city/state into your html just inject in <? Echo $record['valuehere'] ?> where "valuehere" is one of the keys in the array printed out by var_dump, i.e. Country_code, country_code3, ctiy, region, etc.

For anyone else following the thread the $country = getenv(geoip_country_name); stuff that i use only works because they are set as global variables, apparently, so the above method should work regardless of the way your geoip stuff is installed. Mine is just super awesome.


05-16-2012 01:49 AM #24 zeno (Administrator)

Quote Originally Posted by Senator View Post
From CTRtard:

Is referring to the http://j.maxmind.com/app/geoip.js suitable for somebody starting out? At what point would you recommend going with the Pure PHP or the API/PHP extension option?
I would go for PHP from the very beginning because:

a) you're going to need to do it someday, it might as well be now.
b) it is faster/performs better and since it involves PHP it will be much easier to combine with various other PHP functionalities - e.g. inserting country codes etc into tracking subids
c) Javascript is client side so anyone with noscript or javascript disabled/limited isn't going to process the geoip code, and performance/load time is going to vary with the user. Never depend on the users browser if you don't have to. PHP will always be more reliable in this sense.

Getting more comfortable/knowledgeable with PHP will save you time, frustration, money and potentially make you more money. Even just the basics, e.g. subid passing, redirects, geoip stuff, etc.


05-16-2012 01:50 AM #25 zeno (Administrator)

Quote Originally Posted by mrlv View Post
It works thank you thank you thank you thank you sooooo much...
Good to hear man!


05-16-2012 05:48 AM #26 hd2010 (Member)

Quote Originally Posted by zeno
Getting more comfortable/knowledgeable with PHP will save you time, frustration, money and potentially make you more money. Even just the basics, e.g. subid passing, redirects, geoip stuff, etc.
What David said is true, php was created as a web based programming language, it serve us good, understanding of basic php functions will help you alot.


05-16-2012 03:35 PM #27 Senator (Member)

Quote Originally Posted by zeno View Post
Getting more comfortable/knowledgeable with PHP will save you time, frustration, money and potentially make you more money. Even just the basics, e.g. subid passing, redirects, geoip stuff, etc.
Quote Originally Posted by hd2010 View Post
What David said is true, php was created as a web based programming language, it serve us good, understanding of basic php functions will help you alot.
So basically PHP is a programming language where when somebody loads a file.php or html file that has php, it executes the code on your server... In the case of geoip where a database is required, is this all handled by php scripts or like does it interface with something like mysql. Been at this for a couple weeks, need to get something profitable and lots to learn Cheers for the info.


05-16-2012 09:02 PM #28 zeno (Administrator)

Yah PHP is server side so when a client/person browsing requests the file your server processes everything before anything gets sent to their browser, so the user just gets the final output of the PHP. The GeoIP database isn't MySQL related, it's just a text database I think. The GeoIP PHP module you have installed deals with it when it is called by the content of your PHP script.


Home > Programming, Servers & Scripts >