1

I have some code to change my language depending on session

Here is my php code

  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

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

The problem is

When you click on any hyperlink on the site does not work the code, but in the case of pressing a button language site appears well But in the case of pressure on any other hyperlink does not work well site

Web site link: http://www.hh4track.com/

Thanks for helping.

4

1 回答 1

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.'" />';
于 2013-04-21T15:17:52.017 回答