show content based on preferred language

Hi. I’m no guru of php, so I don’t even know if the code I wrote and will show bellow is even right. Can one have ifs inside ifs? If not, what other way do I have to do this?
Apparently it’s not working.

Thanks

[php]<?php
$langcode = substr($_SERVER[‘HTTP_ACCEPT_LANGUAGE’], 0, 2);

if ($_SESSION[‘lang’]==’’)
{ if ($langcode = ‘fr’) { $lang=$langcode; }

else
{ if ($langcode = ‘pt’) {
$lang = ‘pt’; }
else
{ $lang = ‘en’; }
}
}
else {
$lang=$_SESSION[‘lang’];
}
?>[/php]

this is not working either:

[php]<?php
session_start();
$langcode = substr($_SERVER[‘HTTP_ACCEPT_LANGUAGE’], 0, 2);

if ($_SESSION[‘lang’]==’’){
if ($langcode=‘pt’){
$lang=‘pt’;
}
elseif ($langcode=‘fr’){
$lang=‘fr’;
}
else { $lang=‘en’;
}
}

else {
$lang=$_SESSION[‘lang’];
}
?>[/php]

Solved. Realised if clauses should have two == :slight_smile:

[php]<?php
session_start();
$langcode = substr($_SERVER[‘HTTP_ACCEPT_LANGUAGE’], 0, 2);

if ($_SESSION[‘lang’]==’’){
if ($langcode==‘pt’){
$lang=‘pt’;
}
elseif ($langcode==‘fr’){
$lang=‘fr’;
}
elseif ($langcode==‘es’){
$lang=‘es’;
}
else { $lang=‘en’;
}
}

else {
$lang=$_SESSION[‘lang’];
}
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service