Undefined index ve 2 benzer PHP dosyaları?

0 Cevap php

In this file (localization.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;
?>

Ben aşağıdaki uyarı mesajı (localization.php) olsun:

Notice: Undefined index: lang in 

D:\wamp\www\projects\alexchen\alexchen2.0\localization.php on line 23

Ama bu another similar file Ben bu uyarı alamadım:

<?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">

(Vb)

Ben onlar temelde aynı şeyi biliyorum ama neden ilk localization.php dosyadan uyarı alıyorum bir ben? Bunu nasıl düzeltebilirim?

0 Cevap