PHP多语言问题

时间:2013-04-21 13:45:16

标签: php multilingual

我有一些代码可以根据会话

更改我的语言

这是我的PHP代码

  function make_lang(){
      session_start();
      if(isset($_POST['a'])){
          $_SESSION['a']=true;
          unset ($_SESSION['e']);
          unset ($_SESSION['f']);
      }
      if(isset($_POST['e'])){
          $_SESSION['e']=true;
          unset ($_SESSION['a']);
          unset ($_SESSION['f']);
      }
      if(isset($_POST['f'])){
          $_SESSION['f']=true;
          unset ($_SESSION['e']);
          unset ($_SESSION['a']);
      }
  }

  function lang_path(){

      if(!isset($_SESSION['e']) or !isset($_SESSION['f'])){
          include('lan/a.php');
          echo '<link rel="stylesheet" type="text/css" href="css/style-z.php" />';
      }

      if(isset($_SESSION['a'])){
          $lang = "a";
      }

      if(isset($_SESSION['e'])){
          $lang = "e";
      }

      if(isset($_SESSION['f'])){
          $lang = "f";
      }

      $path="lan/".$lang.".php";

      return $path;
  }

  function lang_css(){  
      if(isset($_SESSION['a'])){
          $css = "style-z";
      }

      if(isset($_SESSION['e'])){
          $css = "style-zleft";
      }

      if(isset($_SESSION['f'])){
          $css = "style-zleft";
      }
      $css_i="css/".$css.".css";
      return $css_i;
  }

  make_lang();

  $l_file = lang_path();
  include($l_file);

  $l_css = lang_css();
  echo '<link rel="stylesheet" type="text/css" href="'.$l_css.'" />';

html表单

        <form method="post" class="login-img">
       <input name="e" type="submit" value="English" class="login-img" />
       <input name="a" type="submit" value="Arabic" class="login-img" />
       <input name="f" type="submit" value="Frinch" class="login-img" />
       </form>

问题是

当您点击网站上的任何超链接时代码不起作用,但在按下按钮的情况下语言网站显示效果不错 但在任何其他超链接压力的情况下,网站不能正常工作

网站链接:http://www.hh4track.com/

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

查看您的页面源代码,看起来您正在回显<head></head>标记之外的样式表,并且在<!DOCTYPE ...>标记之前 - 索引页面源代码 -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="tracker" />
<meta name="description" content="" />
<title>HH4track</title>
<link href="css/style-z.css" rel="stylesheet" type="text/css" />
</head>

所有其他页面的源代码 -

<link rel="stylesheet" type="text/css" href="css/style-z.php" /><link rel="stylesheet" type="text/css" href="css/.css" /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
....
</head>

无论点击什么语言链接,您的回音样式表都是 -

<link rel="stylesheet" type="text/css" href="css/style-z.php" />
<link rel="stylesheet" type="text/css" href="css/.css" />

看起来您的语言会话设置不正确。为什么还有3个$_SESSION变量?您可以使用1 - $_SESSION['lang']并简化代码 -

session_start();
function make_lang(){
  if(isset($_POST['a'])){
    $_SESSION['lang']='a';}
  if(isset($_POST['e'])){
    $_SESSION['lang']='e';}
  if(isset($_POST['f'])){
    $_SESSION['lang']='f';}
 }

 function lang_path(){
    if($_SESSION['lang'] == 'a'){
       $lang = "a";}
    if($_SESSION['lang'] == 'e'){
       $lang = "e";}
    if($_SESSION['lang'] == 'f'){
       $lang = "f";}

    $path="lan/".$lang.".php";

    return $path;
 }

 function lang_css(){    
   if($_SESSION['lang'] == 'a'){
      $css = "style-z";}
   else{
      $css = "style-zleft";}

 $css_i="css/".$css.".css";
 return $css_i;
 }


 make_lang();

 $l_file = lang_path();
 include($l_file);

 $l_css = lang_css();
 echo '<link rel="stylesheet" type="text/css" href="'.$l_css.'" />';