4554551n Posted February 13, 2011 Share Posted February 13, 2011 Hello, I made a website, with 3 lang on it, and site works fine (localhost) but when I upload it, default lang is EN and whenever I change lang on the web, let's say from EN to FR, page goes on that lang in this case on FR and redirect me on home page and all text on site is on FR, that's ok, but after that, when I try to click on let's say about us, then on it's own change it back to default lang, and show me that page (about us) but on default lang... Here is sample of code how it's look... This is select.php and I include_once this file on every page... <?php session_start(); header('Cache-control: private'); // IE 6 FIX if(isSet($_GET['lang'])) { $lang = $_GET['lang']; // register the session and set the cookie $_SESSION['lang'] = $lang; setcookie("lang", $lang, time() + (3600 * 24 * 30)); } else if(isSet($_SESSION['lang'])) { $lang = $_SESSION['lang']; } else if(isSet($_COOKIE['lang'])) { $lang = $_COOKIE['lang']; } else { $lang = 'en'; } switch ($lang) { case 'en': $lang_file = 'lang.en.php'; break; case 'fr': $lang_file = 'lang.fr.php'; break; case 'de': $lang_file = 'lang.de.php'; break; default: $lang_file = 'lang.en.php'; } include_once 'lang/'.$lang_file; This is lang.en.php... $lang = array(); // menu $lang['txt1'] = 'Home'; $lang['txt2'] = 'About Us'; $lang['txt3'] = 'Services'; $lang['txt4'] = 'Contact'; It's the same for other two languages... and I simply put in index.php this... <ul> <li><a href="index.php"><em><b><?php echo $lang['txt1'];?></b></em></a></li> <li><a href="about.php"><em><b><?php echo $lang['txt2'];?></b></em></a></li> <li><a href="services.php"><em><b><?php echo $lang['txt3'];?></b></em></a></li> <li><a href="contact.php"><em><b><?php echo $lang['txt4'];?></b></em></a></li> </ul> Let's say again, this kind of code works fine on localhost, but on web not... Any idea why? Thank you. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/227493-multilanguage-site-works-on-localhost-but-not-on-the-internet/ Share on other sites More sharing options...
stijnvb Posted February 13, 2011 Share Posted February 13, 2011 Do you use sessions on your remote host with other scripts? seems like a config problem to me ... Quote Link to comment https://forums.phpfreaks.com/topic/227493-multilanguage-site-works-on-localhost-but-not-on-the-internet/#findComment-1173433 Share on other sites More sharing options...
4554551n Posted February 13, 2011 Author Share Posted February 13, 2011 Yeap, I'm using it in contact us form... cause of captcha image... What should I do? Quote Link to comment https://forums.phpfreaks.com/topic/227493-multilanguage-site-works-on-localhost-but-not-on-the-internet/#findComment-1173540 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2011 Share Posted February 13, 2011 On the actual code on your live site, the page that 'forgets'/resets the language setting when you navigate to it is either having a 'header' error that is preventing the session_start() from working or you are switching the host-name/sub-domain back and forth between a URL that has www. on it and a URL without a www. on it and your session/cookie 'domain' setting is not set to match both URLs or you are switching the path in the URL and your session/cookie 'path' setting is not set to match both paths. What does a phpinfo() statement show for the following settings on both your development system and the live server - output_buffering session.cookie_domain session.cookie_path It would also help if you showed the setcookie() statement you are using. Quote Link to comment https://forums.phpfreaks.com/topic/227493-multilanguage-site-works-on-localhost-but-not-on-the-internet/#findComment-1173611 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2011 Share Posted February 13, 2011 It would also help if you showed the setcookie() statement you are using. LOL, upon further review, I see the one in your posted code. You are not setting the 'path' or 'domain' parameter(s), so the cookie will only be available at the same exact path and host-name/sub-domain where it is set. In your actual code on the live server, are you switching either of those things in the URLs when you navigate between pages that work and don't work? Quote Link to comment https://forums.phpfreaks.com/topic/227493-multilanguage-site-works-on-localhost-but-not-on-the-internet/#findComment-1173631 Share on other sites More sharing options...
4554551n Posted February 13, 2011 Author Share Posted February 13, 2011 Live server version PHP Version 5.2.15: output_buffering no value no value session.cookie_domain no value no value session.cookie_path / / Home server version PHP Version 5.3.1: output_buffering no value no value session.cookie_domain no value no value session.cookie_path / / I'm not sure about that, I mean maybe I don't understand your question, but I'll try to explain... When is on default lang, I can navigate fine, I can go on any page without problems, but problem is when I try to change site into other language(s), let's say I'm on page www.example.com/about.php and I want to see this page on let's say FR, site will redirect me, on www.example.com/index.php?lang=fr (this is ok) and then I can see FR lang on site but only on home page, but when I try to go on www.example.com/about.php then site put back default lang, in this case EN... Strange thing is that this script works fine on localhost... and actually I have this kind of script on other sites too, and there is no problem with it... Maybe it's have something with session_start(); cause on contact.php I have two times session_start(); Any idea? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/227493-multilanguage-site-works-on-localhost-but-not-on-the-internet/#findComment-1173645 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.