嗨,我创建了两个文件交换我的论坛(语言中文和英文)

enForum.php

<?php

     function foo() { 
        global $_COOKIES; 
        setcookie('ForumLangCookie', 'en', time()+3600, '/', '.mysite.com'); 
        echo 'running<br>'; 
        $_COOKIES['ForumLangCookie'] = 'en'; 
        bar(); 
    } // foo() 


    function bar() { 
      global $_COOKIES; 
      if (empty($_COOKIES['ForumLangCookie'])) { 
              die('cookie_name is empty'); 
            } 
            echo 'Language  =' . $_COOKIES['ForumLangCookie'];
            echo "<br>";
    } // bar() 

    foo();


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>forum EN Version</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

please be patient ...
<script LANGUAGE='javascript'>

   location.href='http://www.mysite.com/forum/index.php';

</script>


</body>
</html>

cnForum.php

<?php

     function foo() { 
        global $_COOKIES; 
        setcookie('ForumLangCookie', 'cn', time()+3600, '/', '.mysite.com'); 
        echo 'running<br>'; 
        $_COOKIES['ForumLangCookie'] = 'cn'; 
        bar(); 
    } // foo() 


    function bar() { 
      global $_COOKIES; 
      if (empty($_COOKIES['ForumLangCookie'])) { 
              die('cookie_name is empty'); 
            } 
            echo 'Language  =' . $_COOKIES['ForumLangCookie'];
            echo "<br>";
    } // bar() 

    foo();


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>forum CN Version</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>

please be patient ...
<script LANGUAGE='javascript'>

   location.href='http://www.mysite.com/forum/index.php';

</script>
</body>
</html>

有一些文件,包括 include template('logon');,include template('regist'); 等等,我写一些代码,获得Cookie值和控制流动加载不同模板的文件。

$lang = $_COOKIE["ForumLangCookie"];
// for Debug
// echo '$lang is '.$lang;
// echo '<br/>';

if ($lang == "cn"){
    include template('logon');
}
else if ($lang == "en"){
    include en_template('logon');
}

但有时SetCookie()不工作。我需要加入 Sleep(someSeconds); 我的代码?

有帮助吗?

解决方案

饼干可以访问 $_COOKIE,不 $_COOKIES.

编辑:对不起误解。我建议你改变 $_COOKIES 作为另一个常见的一种使人们可以了解你的问题是否正确。

其他提示

PHP列的名字是$_COOKIE,不$_COOKIES

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top