Forum Moderators: coopster
<?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
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
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
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
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