2011-03-18 14 views
0

風格切換,我有這個簡單的風格swicherPHP和CSS

style.css 

    body.defualt { background-color: RGB(230,197,173); 
       background-image:url("img/defualt.gif") ; 
       background-repeat: no-repeat ; 
       font-family : Lucida Handwriting; 
       color : white; 
} 
body.spring { 
       background-image:url("img/spring.png"); 
       background-repeat: repeat ; 
       font-family : Arial Rounded MT Bold; 

      } 
body.winter{ 
       background-image:url("img/winter.png"); 
       background-repeat: repeat ; 
       font-family : Comic Sans MS; 
       color : RGB(53,31,99); 

      } 

a {text-decoration : none; 
    color :RGB(175,48,175); 
    } 
a:hover {text-decoration :underline ; 
     text-transform: uppercase; 
     } 
現在

當我改變defualt風格它改變 但時許刷新它的迴歸到defualt 我想知道如何拯救我的風格

<?php 
    if ($GLOBALS["language"]==arabic) 
          {include ("ar.php");} 
          else {include ("en.php");} 

?> 
<html > 
    <head> 
     <title> 
      MultiMedia 
     </title> 
     <link rel="stylesheet" type="text/css" href="style.css" /> 
     <script src="function.js" > </script> 
    </head> 
    <body class="defualt"> 
      <br/><br/> 
      <!-- header --> 
      <!-- MultiMedia --> 
      <h1 ><center><?php echo $header ; ?></center></h1> 

      <!-- theme selector --> 
      <table style="position:fixed;left:25px;top:210px;" > 
        <tr> <th> <?php echo $choose?><th> <tr/> 
        <tr> 
         <td align=center> 
          <a onclick ="change('defualt');" title="Defualt" ><img src="img/defualtTHM.gif" style="border-color:white;" border=2 /> </a> 
         </td> 
        </tr> 
        <tr> 
         <td align=center> 
          <a onclick ="change('spring');" title="Spring" ><img src="img/springTHM.png" style="border-color:white;" border=2 /> </a> 
         </td> 
        </tr> 
        <tr> 
         <td align=center> 
          <a onclick ="change('winter');" title="Winter" ><img src="img/winterTHM.png" style="border-color:white;" border=2 /> </a> 
         </td> 
        </tr> 
+0

什麼是JS'變化(..)'做? – Neal 2011-03-18 18:57:03

+0

'if($ GLOBALS [「language」] == arabic)'should'if($ GLOBALS ['language'] =='arabic')'! – ThiefMaster 2011-03-18 18:58:01

+0

好吧沒有關於語言的問題,但我需要讓我的新風格留下來,fanction.js通知有關新款式功能變化(主題){ document.body.className = theme; 警報(主題+「主題開啓」); } – 2011-03-18 19:01:55

回答

0

您可能想要將語言存儲(並設置)爲$_SESSION變量,而不是$_GLOBALS變量。

例如,試試這個:

session_start(); 
$_SESSION['language'] = "arabic"; 

然後,您可以更改$ _SESSION,它會被跟蹤(僅適用於該用戶)跨頁,只要您撥打session_start();您嘗試訪問之前或更改任何$_SESSION變量。

1

保留在會話中。

如果您使用PHP,請將其發送到您的控制器,然後將該值存儲在您的會話中。當你加載PHP文件,檢查您的會話接下來的時間,如果該鍵設置,然後加載CSS文件,否則加載默認

switchstyle.php

$style = isset($_GET['style']) ? $_GET['style'] : false; 
if ($style) { 
    $_SESSION['custom_style'] = $style; 
} 

在index.php文件(假設這是你的鑑於

if (isset($_SESSION['custom_style'])) { 
    //load the style 
} else { 
    //load default style 
} 

注意這只是一個例子/建議,你應該確認您的$ _GET和$ _SESSION檢查,所以你留的保護。

0

這將是很好,如果我們能看到「變」的功能,但我猜你需要這個

<script type="text/javascript"> 
    function change(theme) { 
     var date = new Date(); 
     date.setDate(date.getDate() + 3); // this theme will stay 3 days 
     document.cookie = 'theme=' + theme + '; expires=' + date.toUTCString() 
    } 
</script> 

,並在HTML

<body class="<?=isset($_COOKIE['theme'])?$_COOKIE['theme']:'default'?>"> 
+0

非常非常非常非常非常非常非常非常感謝 – 2011-03-18 19:34:12