Home > Programming, Servers & Scripts >

How do I get Geoip to work with beyond hosting? (12)


01-03-2012 07:45 PM #1 shishkabob (Member)
How do I get Geoip to work with beyond hosting?

I want to use visitors' city,state on a landing page.

I emailed beyond hosting and they told me geoip was already installed and to use the functions on this page to call them http://php.net/manual/en/book.geoip.php

I'm a noob, I know basic html, can figure out java script, no idea what to do here. I've googled trying to find more tutorials but they are all based of this site. I've copy and pasted exact code and slightly modified code and can't get anything to pop up on LP.

What is the script I have to use to be able to display the city,state of user?


01-03-2012 07:52 PM #2 wright (Member)

use the javascript posted by besmir

http://stmforum.com/forum/showthread...highlight=part

It's a bit outdated, you can view all the functions it gives you by just calling the script
http://j.maxmind.com/app/geoip.js


01-03-2012 08:01 PM #3 godspeed (Member)

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

Than, where you want to appear:

region:
<script language="JavaScript" type="text/javascript">document.write(geoip_region_name());</script>

city:
<script language="JavaScript" type="text/javascript">document.write(geoip_city());</script>


01-03-2012 08:07 PM #4 deedsmedia (Member)

Here is the official documentation: http://www.maxmind.com/app/javascript_city


01-03-2012 09:26 PM #5 shishkabob (Member)

Yeah, that's the one I know how to use, but want one that goes to geoip on my site and not maxmind.

Does anyone know how to use the php one in the link in OP?

Thanks


01-03-2012 09:50 PM #6 bbrock32 (Administrator)

If you want to use the PHP one it's pretty easy ( however keep in mind results will be the same with the javascript if you use the free version ).

Put this code on the top of your landing page :

[PHP]
<?
$ip=$_SERVER['REMOTE_ADDR'];
$record = geoip_record_by_name($ip);
$country=$record['country_code'];
$region=$record['region'];
$city=$record['city'];
?>
[/PHP]

Now , put this code where you want the city / region to be displayed :

HTML Code:
My city is <?=$city?>
My region is <?=$region?>


01-04-2012 01:37 AM #7 heavyt (Senior Member)

If you are running a page with alot of traffic don't use maxminds link to their js they will block you lol, found this out the hard way.


01-04-2012 01:45 AM #8 polarbacon (Moderator)

Quote Originally Posted by heavyt View Post
If you are running a page with alot of traffic don't use maxminds link to their js they will block you lol, found this out the hard way.
on the same note....cuz its in the <head> section it can cause slow loads...

Highly recommend using the PHP bbrock posted above


01-04-2012 09:06 AM #9 wright (Member)

Quote Originally Posted by polarbacon View Post
on the same note....cuz its in the <head> section it can cause slow loads...

Highly recommend using the PHP bbrock posted above
When the Browser hits JavaScript on its way through the page it blocks everything.

Luckily you can put the Javascript anywhere, so I recommend putting it where all of the visual stuff has already loaded, as far down the page as possible. There's absolutely no reason to put it in the <head>:

Code:
  <body>
    <div id="wrapper">

    <All the stuff that makes up your LP>

    <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"</script>
    <script language="JavaScript">
      var country=geoip_country_name();
      var region=geoip_region();
      var city=geoip_city();
      if(country=="")
      country="US";
      if(region=="")
      region="New York";
      if(city=="")
      city="New York";
    </script>
	<p><script language="JavaScript">document.write(city+ ', ' +region);</script></p>
      </div>
	<div align="center" class="p-small">Copyright</div>
</div>
<script src="tracking" type="text/javascript"></script>
    </body>


01-04-2012 11:21 PM #10 consumercpa (Member)

You could use our API for GEO IP Location, you just need to create an account at ProxyDeter.com and then you do the following:

<?php
$api = "YOUR_KEY"; // Your API key
$ip = $_SERVER['REMOTE_ADDR']; // IP Address
$type = "name"; // This can be code or name. Code will display the country code (US), and Name will display the countries name (United States)

$results = file_get_contents('http://www.proxydeter.com/api/country.php?api='.$api.'&ip='.$ip.'&'.$type);
$results = simplexml_load_string($results);

if (isset($results->errors))
{
echo $results->errors;
}
else
{
echo $results->country;
}
?>


01-09-2012 11:28 PM #11 successliv (Member)

Is the geolite city database accurate enough for PPV?

if using the PHP posted above is REMOTE_ADDR = /usr/local/share/GeoIP/GeoIPCity.dat (where I installed the date file) of the geocities lite?

I guess I need to figure out how to install the mod_geoip which means I need to figure out how to install the rpm package for apxs?

Thanks


01-10-2012 03:49 AM #12 consumercpa (Member)

successliv, Yeah geolite city database should work fine. As for installing it.. I didn't need to modify my server any at all.


Home > Programming, Servers & Scripts >