简体   繁体   English

多语言的PHP问题

[英]PHP problems with multilanguage

I have problems with php multilanguage. 我有php多语言的问题。 I'm using function *check_lang* and it works fine in one page, but once I go to another page the $_SESSION['lang'] variable $lang turns back into default (en). 我正在使用* check_lang *函数,它在一页中可以正常工作,但是一旦我转到另一页,$ _SESSION ['lang']变量$ lang就会变回默认值(en)。 What is the problem? 问题是什么?

<?php

    function check_lang() { 
    if(isset($_GET['lang'])
        {
        $lang = $_GET['lang'];
        $_SESSION['lang'] = $lang
        }

    if (!isset($_SESSION['lang'])) { 
        $lang = 'en'; 

    } else { 
        $_SESSION['lang']=$lang; 
      } 

    //directory name 
    $dir = 'languages'; 
    return "$dir/$lang.lng"; 
    } 

    ?>

You have to: 你必须:

session_start();

At the top of each of your scripts in which you want to use session variables. 在您要使用会话变量的每个脚本的顶部。

You need to call session_start() on each page you're planning on using the $_SESSION[] global in. That's what tells PHP that it should look up the session_id from the user's cookies or the query string so that PHP knows which session's values to use. 你需要在你计划使用$ _SESSION []全局的每个页面上调用session_start()。这就是告诉PHP它应该从用户的cookie或查询字符串中查找session_id以便PHP知道哪个会话的值使用。

Reference . 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM