freakstyling Posted March 14, 2012 Share Posted March 14, 2012 Hi again very helpful people! I´ve got my page set up for switching between English and Spanish. The problem is I can´t switch the languages on the page itself. Only when I use IE and Mac, it goes to the Spanish version. With the rest, Chrome, Firefox, it goes to the English version. I´m thinking it´s maybe a preset, maybe something to do with $_SESSION . When I press the button to switch it gives the right link, but doesn´t change language... Hope I made it clear more or less, otherwise ask me... maybe something to do with this...? <?php session_start(); $_rootPath = dirname(__FILE__); // Root path per als includes / require's $_version = 22; // Versió de la pàgina, força que s'hagin de recarregar les imatges que estiguin en cache. $_availableLanguages = array('es', 'en'); // Idiomes disponibles $_picturesMediaPath = "pictures/"; require_once($_rootPath . '/lib/db.php'); require_once($_rootPath . '/lib/lang.utils.php'); if( isset($_GET['lang']) && languageIsAvailable($_GET['lang']) ) { $_lang = $_GET['lang']; $_SESSION['lang'] = $_lang; } else if( isset($_SESSION['lang']) ) { $_lang = $_SESSION['lang']; } else { $l = getPreferredUserLanguage(); if($l) $_lang = $l; } // Clear cache Header("Cache-control: private, no-cache"); Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT"); Header("Pragma: no-cache"); ?> or this...? <?php /* REQUIREMENTS $_availableLanguages array of all available languages. */ function languageIsAvailable($l) { global $_availableLanguages; return ( in_array($l, $_availableLanguages) ); } function getPreferredUserLanguage() { if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ) { $acceptedlanguages = strtolower( str_replace(' ', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]) ); $acceptedlanguages = explode( ",", $acceptedlanguages ); foreach ( $acceptedlanguages as $l ) { $aLanguage = substr( $l, 0, 2 ); if ( languageIsAvailable($aLanguage) ) { return $aLanguage; } } } return false; } ?> Thanks again everybody for your help. You´re great! Quote Link to comment https://forums.phpfreaks.com/topic/258915-page-doesn%C2%B4t-switch-languages-but-loads-the-right-lang-with-browser-preset/ Share on other sites More sharing options...
freakstyling Posted March 14, 2012 Author Share Posted March 14, 2012 Got it! Mistake in the links I made to switch languages, Thnx anyway! Quote Link to comment https://forums.phpfreaks.com/topic/258915-page-doesn%C2%B4t-switch-languages-but-loads-the-right-lang-with-browser-preset/#findComment-1327364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.