doute7910 2016-03-09 04:39
浏览 8
已采纳

如何在PHP上制作多语言?

I want to perform multi-language of my site , but My code only work once and cannot work any more can anyone help me?

Main Site

  1. ...
  2. <?php if ($_SESSION['lang']=='hk'){
  3. include_once 'lang/lang.hk.php';
  4. }else {
  5. include_once 'lang/lang.en.php';
  6. }
  7. ?>
  8. ...
  9. <a href="redirect/hk.php">中文</a>
  10. ...
  11. <div class="panel-heading"><?php echo $lang['ABC']; ?></div>

redirect/hk.php

  1. <?php
  2. $_SESSION['lang']=='hk';
  3. header("location:http://example.com/");
  4. ?>

lang.hk.php

  1. $lang = array();
  2. $lang['ABC'] = 'XXXX';

lang.en.php

  1. $lang = array();
  2. $lang['ABC'] = 'Hello';

I click "hk.php" many times but the site still show "Hello" , But when I set that $lang="hk" manually , it works. How can I fix it ??

展开全部

  • 写回答

1条回答 默认 最新

  • dreamy6301 2016-03-09 06:07
    关注

    Both Naruto and Fred -ii- are rights.

    You have to put a session_start() at the top of your index.php and redirect/hk.php and modify this with :

    $_SESSION['lang'] = 'hk';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部