在這個文件(localization.php):未定義的索引和2個類似的PHP文件?
<?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';
}
// use appropiate lang.xx.php file according to the value of the $lang
switch ($_SESSION['lang']) { //line 23
case 'en':
case 'es':
case 'zh-tw':
case 'zh-cn':
$lang_file = 'lang.'.$_SESSION['lang'].'.php';
break;
default:
$lang_file = 'lang.en.php';
}
//localization helper function
function l($localization) {
global $lang;
return $lang[$localization];
}
include_once 'languages/'.$lang_file;
?>
我得到以下警告消息(localization.php):
Notice: Undefined index: lang in
d:\ WAMP \ WWW \項目\ alexchen \ alexchen2.0 \ localization.php on line 23
但是在這另一個類似的文件我沒有得到警告:
<?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';
}
// use appropiate lang.xx.php file according to the value of the $lang
switch ($lang) {
case 'en':
$lang_file = 'lang.en.php';
break;
case 'es':
$lang_file = 'lang.es.php';
break;
case 'zh-tw':
$lang_file = 'lang.zh-tw.php';
break;
case 'zh-cn':
$lang_file = 'lang.zh-cn.php';
break;
default:
$lang_file = 'lang.en.php';
}
//translation helper function
function l($localization) {
global $lang;
return $lang[$localization];
}
include_once 'languages/'.$lang_file;
?>
的index.php:
<?php
include_once 'localization.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta name="robots" content="index, follow"/>
<meta name="description" content="Web design and Translation/網頁設計和翻譯" />
<meta name="keywords" content="web development, web developer, web design, web designer, translation, translator, taiwan, taipei, taichung, english, chinese, spanish, 網站開發者, 網頁設計, 網頁設計師, 翻譯, 翻譯著, 臺灣, 臺北, 臺中, 英文, 中文, 西班牙文, html, css, javascript, php" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title>Alex Chen - Web design and Translation/網頁設計和翻譯</title>
<link rel="stylesheet" type="text/css" href="styles/reset.css" />
<link rel="stylesheet" type="text/css" href="styles/global.css" />
<link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.3.1.css" />
<?php if($lang_file=='lang.zh-tw.php' || $lang_file=='lang.zh-cn.php') {echo '<link rel="stylesheet" type="text/css" href="styles/chinese.css" />';} ?>
</head>
<body id="home">
<div id="header">
<div class=
"container">
(等)
我知道他們這樣做基本上是相同的,但爲何我從第一個localization.php文件獲取警告?我該如何解決它?