Hello, I would like to geo target US users based on their state. How can i do this. ( im using wordpress )
You can use the MaxMind databases. They have a free city database that should work for getting the state >> http://www.maxmind.com/app/geolitecity I wrote a really basic tutorial on how to get it working here (using the country database, should be the same for city) >> http://www.thewebsiteprofessionals.com/geo-targeting.html Just follow my tutorial, and use this city file(GeoLiteCity.dat.gz) instead of the country file (GeoIP.dat.gz). --- 14 posts and a member since 2004? Wow
Thanks for the reply. I downloaded both files and uploaded to my server. But im not sure what to use instead of get_country_code in your script. Would like to redirect users to another page, based on their state. Not the most active member, but still more than 1 post per year
Hmmm... looks like it's quite different using the city database than the country database. I just did some quick digging around the MaxMind site. Looks like you'll need geoipcity.inc for using the city database (instead of geoip.inc). Get it here > http://geolite.maxmind.com/download/geoip/api/php/ Also.. this might help get it working > http://geolite.maxmind.com/download/geoip/api/php/sample_city.php MaxMind need some decent documentation. It's kinda hit and miss trying to get it to work, but when it does finally work, it's reasonably reliable *AND FREE*. There must be a simpler alternative though.
So i "constructed" a script like this. Changed country_code to city. But it will show me an error like this: Fatal error: Call to undefined function geoip_city_by_addr() in ---------- <? function get_city ($ip) { include_once("geoipcity.inc"); $gi = geoip_open(dirname(__FILE__)."/GeoLiteCity.dat",GEOIP_STANDARD); $city = (geoip_city_by_addr($gi, $ip)) ; geoip_close($gi); return $city; } $userlocation = (get_city($_SERVER["REMOTE_ADDR"])); echo $userlocation; ?>
Probably not worth trying to get my code to work, as it's meant for the country database. Did you try this > http://geolite.maxmind.com/download/geoip/api/php/sample_city.php
it shows me US USA United States NY New York Binghamton 42.1393 -75.8798 502 607, which is really very far from truth
So you got it running at least? Are you in the US? If not, check it from some US based proxies and see what it says. You may need to divert non-US traffic before they hit your US centric geo targeting page. I bet there's an easier way to do this that neither of us know about.
I guess its almost working It shows the excact same location also from proxies. Im in Kuala Lumpur at the moment, so very far away from NY.
I found a plugin for WP that uses maxmind database, so i can use codes like [mmjs-region] inside the posts. ( and its working nice this time ) Can i somehow redirect users to region specific page with this info ? For example if NY, it will redirect to www.mydomain.com?cat=3 automatically.
What's the WP plugin? You should easily be able to serve up specific content using php to read the variable in the url. Something like... $category = $_GET['cat']; if ($category==3){echo "HELLO NEW YORK!";} PHP:
The plugin is: http://www.wp-geolocation.com But as for the script, i want to redirect them to entirely different page.
If you can get it to echo out "HELLO NEW YORK", then you can do anything maybe something like (in the header of your WP theme)... $category = $_GET['cat']; if ($category==3){ header('HTTP/1.1 301 Moved Permanently'); header("Location: http://www.mydomain.com/newyork.html"); } PHP: I haven't tried the WP plugin yet, so I'm just throwing darts out the window here ....
This might be a stupid question but can i do something like this: if ([mmjs-city]=New York){ header('HTTP/1.1 301 Moved Permanently'); header("Location: http://www.mydomain.com/newyork.html"); ?>
Google provides a local search as well as a Global search. Also you can get more specific by targeting a specific state or country and submit to a local business site. Have them list your site.