doudai3012 2013-06-24 21:03
浏览 23
已采纳

根据会话数据更改样式表

Ok I have a session started within my application and it gets a session variable that defines a theme.

I have this code, but it doesn't seem to be working at all. Basically I want this to select the correct stylesheet based on the theme the user chose at registration. So if they selected the Default theme I would need the default css file to be linked and so on...

I am fairly new to PHP so if it's completely wrong, tell me but please help and tell me what's wrong. We all start somewhere.

<?php 
$themeName = '$_SESSION["SESS_THEME_NAME"]';
if ($themeName == "Default") {
    echo '<link rel="stylesheet" type="text/css" href="mws-theme.css" />';
}
if ($themeName == "Army") {
    echo '<link rel="stylesheet" type="text/css" href="mws-theme-army.css" />';
}
if ($themeName == "Rocky Mountains") {
    echo '<link rel="stylesheet" type="text/css" href="mws-theme-rocky.css" />';
}
if ($themeName == "Chinese Temple") {
    echo '<link rel="stylesheet" type="text/css" href="mws-theme-chinese.css" />';
}
if ($themeName == "Boutique") {
    echo '<link rel="stylesheet" type="text/css" href="mws-theme-boutique.css" />';
}
if ($themeName == "Toxic") {
    echo '<link rel="stylesheet" type="text/css" href="mws-theme-toxic.css" />';
}
if ($themeName == "Aquamarine") {
    echo '<link rel="stylesheet" type="text/css" href="mws-theme-aquamarine.css" />';
}

?>
  • 写回答

2条回答 默认 最新

  • donglaoping9702 2013-06-24 21:04
    关注

    Remove the single quotes.. http://php.net/manual/en/language.variables.php

    $themeName = $_SESSION["SESS_THEME_NAME"];

    If that doesn't work, make sure that you have started the session http://php.net/manual/en/function.session-start.php

    session_start()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?