0

I have problem with language on my page. When i choose one language it take it corectly, all content change, but when i reload or go to another page the language change back to default language, something with cookies are not corect :/. On localhost all works good but on hosting dont work.

Code:

<?php
session_start();
header('Cache-control: private');

if(isSet($_GET['lang']))
{
    $lang = $_GET['lang'];

    $_SESSION['lang'] = $lang;
    session_set_cookie_params('lang', $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
    $lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
    $lang = $_COOKIE['lang'];
}
else
{
    $lang = 'lv';
}

switch ($lang) {
  case 'lv':
      $lang_file = 'lv.php';
      break;
  case 'ru':
      $lang_file = 'ru.php';
      break;
  default:
      $lang_file = 'lv.php';
}

include_once 'lang/'.$lang_file;
?>
mmcclannahan
  • 1,608
  • 2
  • 15
  • 35
Arvis
  • 269
  • 1
  • 3
  • 9
  • Are you sure you've uploaded everything correctly? Is the ru.php on the server up to date? – OIS Oct 02 '13 at 17:51
  • Are you setting the language each time you hit the page? You're getting the language from the URL I assume? Perhaps post the URL you're testing with? Another possibility is your host doesn't allow you to mess with the $_SESSION are you getting any errors? – mmcclannahan Oct 02 '13 at 17:52
  • Yes, i uploaded all corectly. – Arvis Oct 02 '13 at 17:54
  • @mam8cc No, i dont get any errors :/, i set the language and its saves on localhost, and i can go to all my pages, but on hosting they just drop language to default. – Arvis Oct 02 '13 at 17:57
  • Could you please post the URL you are using to test? i.e. http://localhost:8000/?foo=bar – mmcclannahan Oct 02 '13 at 18:14

2 Answers2

0

I suggest to check the answers here:

PHP Session data not being saved

Code that you showed us works well, so it must be a server/configuration issue. Good luck :)

Community
  • 1
  • 1
Arius
  • 1,387
  • 1
  • 11
  • 24
0

Why are you using session_set_cookie_params and not setcookie?

Adding the ?lang parameter on every link is going to be tiresome. And bloat your code and make it less readable.

Zonker.in.Geneva
  • 1,389
  • 11
  • 19