Author Topic: Based on IP Address - Change Language  (Read 7263 times)

0 Members and 1 Guest are viewing this topic.

drhtm

  • Guest
Based on IP Address - Change Language
« on: May 30, 2005, 11:02:13 PM »
I have three different languages set up on my site and my default langauge is english.  But I like to have my site change to the respective language when the user is from a particular region of the world.  Is this possible?  I know google.com's homepage does it.


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Based on IP Address - Change Language
« Reply #1 on: May 30, 2005, 11:23:00 PM »
we have a mod that let visitors chose a language from the avalable language list.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

drhtm

  • Guest
Re: Based on IP Address - Change Language
« Reply #2 on: May 31, 2005, 12:01:29 AM »
that's true and i have all those wonderful mods (from you!)...but for new visitors, instead of showing the default language, i like to show the language that's most appropriate based on IP address.  They can still change it but this way, if someone from france visits my site, then the site will be in french automatically as opposed to english first.  I just think giving users the utmost service would be great.

Is this possible?

drhtm

  • Guest
Re: Based on IP Address - Change Language
« Reply #3 on: July 04, 2005, 01:48:52 AM »
So after searching high and low, I found a free script that provides a way to redirect users based on geographical region of visitors to our site.

Here is the site: http://www.ip2nation.com/ip2nation

However, I'm having some trouble implimenting it on my site.

I downloaded and added their database file.  Then I manipulated their redirect script:
Code: [Select]
$sql = 'SELECT
            country
        FROM
            ip2nation
        WHERE
            ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
        ORDER BY
            ip DESC
        LIMIT 0,1';

list($country) = mysql_fetch_row(mysql_query($sql));

switch ($country) {
case 'br':
// Get the brazilians to a portuguese version of yoursite
header('Location: http://www.yoursite.com/?l=portuguese');
exit;
default:
// The rest can go to the engish version
header('Location: http://www.yoursite.com/?l=english');
exit;
}

and I added this code to the end of this file: includes/page_header.php. 

Now, when I enter my site, it says something that the redirect limit has exceeded...am I doing this right? should I put this bit of info in our sessions.php file? if so, can someone help guide me...i really want this and think it's very useful for a lot of users here who use multilanguage feature of 4images.

drhtm

  • Guest
Re: Based on IP Address - Change Language
« Reply #4 on: July 04, 2005, 11:16:02 PM »
i added it to the sessions.php file and i get this error

Quote
Redirection limit for this URL exceeded. Unable to load the requested page.  This may be caused by cookies that are blocked.

then if i comment that piece of code, and reupload, there's no problem...does anyone know what this error means and how i can fix it and have this script added to my site?

TheOracle

  • Guest
Re: Based on IP Address - Change Language
« Reply #5 on: July 05, 2005, 06:42:34 AM »
Quote

Redirection limit for this URL exceeded. Unable to load the requested page.  This may be caused by cookies that are blocked.


I already explained this issue ' but ' in the french section (understandable). ;)

The reason why you're having this bug is due to Firefox issues (which also blocks by using IE - once executed from Firefox during the first load).

Resolution :

Quote

header('Location: http://www.yoursite.com/?l=portuguese');
header('Location: http://www.yoursite.com/?l=english');


for :

Code: [Select]

die (header('Refresh: 0; url=http://www.yoursite.com/?l=portuguese'));
die (header('Refresh: 0; url=http://www.yoursite.com/?l=english'));


This will apply the same action as you requested and should ' definitely ' clear out this cookie problem.

drhtm

  • Guest
Re: Based on IP Address - Change Language
« Reply #6 on: July 05, 2005, 02:15:57 PM »
thanks but it didn't work for me.  I tried using IE and then my site just kept refreshing over and over...should i put that piece of code in my sessions or page_header?

TheOracle

  • Guest
Re: Based on IP Address - Change Language
« Reply #7 on: July 05, 2005, 02:20:44 PM »
Quote

I tried using IE and then my site just kept refreshing over and over


Right. I just modified my post above.

drhtm

  • Guest
Re: Based on IP Address - Change Language
« Reply #8 on: July 05, 2005, 02:32:06 PM »
TheOracle,

Thanks for helping me out, but i'm still getting the same problem, it just keeps reloading...both on my firefox and IE.  I tried changing the url to http://www.cnn.com and it redirects fine, but if i add the language part, it just keeps reloading...

TheOracle

  • Guest
Re: Based on IP Address - Change Language
« Reply #9 on: July 05, 2005, 02:38:25 PM »
Quote

but if i add the language part, it just keeps reloading...


Ah ! so now this question can be answered :

Quote

should i put that piece of code in my sessions or page_header?


Since the $l is being used from page_header.php, you should try it on that file. ;)