Forum Moderators: coopster

Message Too Old, No Replies

geo targeting content shifting

code help needed

         

benevolent001

11:35 am on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello friends , i have this code to how content based upon the location of user

<?php
// make a valid request to the hostip.info API
if ($_SERVER['HTTP_X_FORWARD_FOR']) {
$ip = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}

$url = "http://api.hostip.info/country.php?ip=".$ip;

// fetch with curl
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$country = curl_exec($ch);

curl_close ($ch);

// display according geotarget
if ($country == "US") {

print "usa content";

}
else {
print"g";
}
?>

it works fine

There are few issues with it

1) It queries third party website every time , makes it bit slow

I tried to install mod_geoip on server but wasnt able to do it. see my this post [webmasterworld.com...]

2) so i have only this option left to use i guess

-----------------------

So here is in what i need help

I want to make include file , which i will put in my header and then just use this code in the page

if ($country == "US") {

print "usa content";

}
else {
print"g";
}

this part of code to show the relevant content

how can i do this ,

i had doubt will server will check each time the new page is asked for ip to the third part website?

Do i any better options with me , thanks lot for your assistance.

With Regards

omoutop

1:10 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well you can still use your firt option...

google for ip-to-gountry.

this handy utility, creates a databse with almost all ips.
after that, check your databse for user's ip, and redirect him accodingly.

benevolent001

1:54 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi
thanks for your reply

i need help in this respect

I want to make include file , which i will put in my header and then just use this code in the page

if ($country == "US") {

print "usa content";

}
else {
print"g";
}

this part of code to show the relevant content

how can i do this ,

i had doubt will server will check each time the new page is asked for ip to the third part website?

Do i any better options with me , thanks lot for your assistance.

With Regards

jatar_k

2:18 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



in the past I have used sessions to track this, yes on every first request you have to find the country but then you store it in the session and can check for the existance of that var before you make the geo request

this doesn't help with spiders though, you will have to make the request each time. A spider could probably bring down your site if it was indexing heavily.

delivering different content on the exact same url might be a bit of an issue anyway

as omoutop mentioned ip-to-country, which I've used with success, is a good option, at least then it will be local and won't rely on a third party for the result

benevolent001

2:29 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i am using drupal CMS for managing website , i really dont want to create separate websites for various countries when i know i can serve all with almost same product but with different flavours

i am thinking to just divide my traffic into two parts

one is mainly creamy traffic of US , UK , CA etc...and rest for other few countries

based upon country i want to make just make some changes in the content for just 5-6 pages

Rest of my website is just forum which can serve all the people around the world.

But those 5-6 pages i just want to make really good and custom to flavour of people around th world

i am thinking to add that switch for just 5-6 pages

Another idea which struck just now in my mind is to create separate pages for all group of countries and make custom navigation for each of that group , Drupal makes its easy to show up custome navigation and i make check there for which navigation should be presented

I am not into php , i wish i knew atleast one programming language i would have done lot of good stuff myself

jatar_k

2:40 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> create separate pages for all group of countries and make custom navigation for each of that group

that would be a good solution

omoutop

3:53 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



or you can use template-like pages with translation for the languages you need...

example:
file: languages.php

if ($country="") {$country="english"};

//english vars
if ($country=="english")
{
$var1 = "hello world";
$var2 = "this is in english";
}

if ($country=="other")
{
$var1 = "hello world in other language";
$var2 = "this is in english in other language";
}

////
include this file in your pages
Now in your pages, wherever you have text, just echo the appropriate $var{x}

Hope you get my point