1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Language depending on cookie or browser

Discussion in 'PHP' started by jmansa, Oct 7, 2008.

  1. #1
    I have a script which generates a langaugefile like this:
    		$sql = $db->sql_query("SELECT * FROM ".$prefix."_lang_code WHERE lang_id=2");
    		while ($row = $db->sql_fetchrow($sql)) {
    		
    		define("_".$row['tagname']."","".$row['string']."");
    		echo 'Tagname: _'.$row['tagname'].' | Text: '.$row['string'].'<br>';
    		
    		}
    PHP:
    As you can see it generates the language depending on "lang_id".

    I want it to choose which lang_id it should use depending on first, if a cookie is active with the preferred language like this:
    $cookie_read = explode("|", base64_decode($user));
              //define variables to hold cookie values.
              $userid = $cookie_read[0];
              $language = $cookie_read[6];
    PHP:
    If the cookie is not set it should look at what language browser is like this:
    $browser_lang = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
    PHP:
    And if the browsers lang is unsupported it should go to the default language which is lang_id=1.

    I have a db table (".$prefix."_lang_languages) with the installed language with these fields(id, lang_long, lang_short) where the lang_short field is the field that matches the browser lang id (en, de, da, se, etc...)

    Can this be done and if yes... how? Hope somebody can help or guide me in the right direction :)
     
    jmansa, Oct 7, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175