Jump to content
php.lv forumi

Valodas izvēle


m0zus

Recommended Posts

<?php 
if ($_COOKIE["dream_lang"] = ru) {include 'lang/ru.php';}
elseif ($_COOKIE["dream_lang"] = lv) {include 'lang/lv.php';}
elseif ($_COOKIE["dream_lang"] = en) {include 'lang/en.php';}
else {include 'lang/en.php';}
?>

Var kads pateikt kas seit ir nepareizi? Vins includo tikai ru.php kaut cookijs ir lv ...

Link to comment
Share on other sites

Vispār labāk lietot switch:

<?php
if($_REQUEST['set_lang']){
if($_REQUEST['set_lang'] == "lv" OR $_REQUEST['set_lang'] == "en" OR $_REQUEST['set_lang'] == "ru"){
setcookie("dream_lang",$_REQUEST['set_lang']);
}
}


switch($_COOKIE["dream_lang"]){
case 'en':
//anglju valoda - ja izveeleeta
include("lang/en.php");
break;
case 'lv':
//latvieshu valoda, ja izveeleeta
include("lang/lv.php");
break;
case 'ru':
//krievu valoda, ja izveleta
include("lang/ru.php");
break;
default:
//galvenaa valoda
include("lang/en.php");
break;
}
?>

<a href="<?php echo $_SERVER['PHP_SELF']; ?>?set_lang=lv">Mainīt valodu uz LV</a> 
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?set_lang=en">Mainīt valodu uz EN</a> 
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?set_lang=ru">Mainīt valodu uz RU</a>

Edited by ok1
Link to comment
Share on other sites

×
×
  • Create New...