The code works when I declare $lang
like this (at the top of the index file):
index.php (with php variable declaration at the top):
<?php
$lang = 'es';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title>New Project</title>
<link rel="stylesheet" type="text/css" href="styles/global.css" />
</head>
<body id="home">
<div id="header">
<div class="container">
<div id="header-top">
<h1><a href="http://widerdesign.co.nr/">wider design</a></h1>
<ul id="lang">
<li><a href="index.php?lang=en" <?php if($lang=='en') {echo 'class="current"';} ?>>English</a></li>
<li><a href="index.php?lang=es" <?php if($lang=='es') {echo 'class="current"';} ?>>Español</a></li>
<li><a href="index.php?lang=tw" <?php if($lang=='tw') {echo 'class="current"';} ?>>中文(繁體)</a></li>
<li><a href="index.php?lang=cn" <?php if($lang=='cn') {echo 'class="current"';} ?>>中文(简体)</a></li>
</ul>
but it doesn't work when its declared in a included file:
index.php (with included file which has the php variable declaration):
<?php
include_once 'common.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title>New Project</title>
<link rel="stylesheet" type="text/css" href="styles/global.css" />
</head>
<body id="home">
<div id="header">
<div class="container">
<div id="header-top">
<h1><a href="http://widerdesign.co.nr/">wider design</a></h1>
<ul id="lang">
<li><a href="index.php?lang=en" <?php if($lang=='en') {echo 'class="current"';} ?>>English</a></li>
<li><a href="index.php?lang=es" <?php if($lang=='es') {echo 'class="current"';} ?>>Español</a></li>
<li><a href="index.php?lang=tw" <?php if($lang=='tw') {echo 'class="current"';} ?>>中文(繁體)</a></li>
<li><a href="index.php?lang=cn" <?php if($lang=='cn') {echo 'class="current"';} ?>>中文(简体)</a></li>
</ul>
common.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 'es':
$lang_file = 'lang.es.php';
break;
case 'tw':
$lang_file = 'lang.tw.php';
break;
case 'cn':
$lang_file = 'lang.cn.php';
break;
default:
$lang_file = 'lang.en.php';
}
include_once 'languages/'.$lang_file;
Is $lang
really having any value when its declared in the common.php
file?
edit: the language change in the file is working is just the class .current not being activated, weird.