CSS theme changer?

Discussion in 'PHP' started by crazyryan, Oct 15, 2006.

  1. #1
    Can anyone point me in the direction of acss theme changer? thanks.
     
    crazyryan, Oct 15, 2006 IP
  2. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This can be done quite simlply. Code such as the following in the head section of your documents should work

    <?php
    
    session_start();
    
    if(isset($_GET['theme'])) {
    	$_SESSION['theme'] = $_GET['theme'];
    	}
    
    switch($_SESSION['theme']) {
    	case 1:
    	echo "<link rel='stylesheet' type='text/css' href='1.css' />";
    	break;
    	case 2:
    	echo "<link rel='stylesheet' type='text/css' href='2.css' />";
    	break;
    	case 3:
    	echo "<link rel='stylesheet' type='text/css' href='3.css' />";
    	break;
    	default:
    	echo "<link rel='stylesheet' type='text/css' href='default.css' />";
    }
    
    
    ?>
    PHP:
    Then you link to the different styles using links such as yoursite.com/index.php?theme=1

    The preference is stored in the session variables. This method relies on cookies (unless you include the session id in the url) but if they don't have cookies enabled they'll still get your default css file.
     
    streety, Oct 15, 2006 IP
  3. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    penagate, Oct 15, 2006 IP
  4. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #4
    Thanks :)

    There seems to be an error though. I placed it in the head and got a session error.

    
    [B]Warning[/B]:  session_start() [[URL="http://www.habboname.com/function.session-start"]function.session-start[/URL]]: Cannot send session cookie - headers already sent by (output started at /home/spiral/public_html/habbo/halloween.php:4) in [B]/home/spiral/public_html/habbo/halloween.php[/B] on line [B]7[/B]
    
    [B]Warning[/B]:  session_start() [[URL="http://www.habboname.com/function.session-start"]function.session-start[/URL]]: Cannot send session cache limiter - headers already sent (output started at /home/spiral/public_html/habbo/halloween.php:4) in [B]/home/spiral/public_html/habbo/halloween.php[/B] on line [B]7[/B]
    Code (markup):
    This is the start of my code if it helps.

    <!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=iso-8859-1" />
    <title>» <?php include("name.php"); ?> - homepage</title>
    <?php include("meta.php"); ?>
          <?php
          session_start();
          if(isset($_GET['theme'])) {
              $_SESSION['theme'] = $_GET['theme'];
              }
         switch($_SESSION['theme']) {
              case 1:
              echo "<link rel='stylesheet' type='text/css' href='style.css' />";
              break;
              case 2:
              echo "<link rel='stylesheet' type='text/css' href='stylenormal.css' />";
              break;
              default:
              echo "<link rel='stylesheet' type='text/css' href='default.css' />";
          }
          ?> 
    </head>
    <body>
    
    <div id="container">
    
    <div id="top-bar" class="title"><b><?php include("name.php"); ?></b>
      <div id="console"><?php include("top.php"); ?></div>
    </div>
    
    <div id="banner">
    
    <div id="left">
    <?php include("nav.php") ?>
    </div>
    
    
    <div class="right">
    
    <div id="r-top"><?php include("slogan.php") ?></div>
    <div class="r-content">
    PHP:
     
    crazyryan, Oct 16, 2006 IP
  5. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #5
    session_start() needs to be called before any output is sent.
     
    penagate, Oct 16, 2006 IP
  6. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #6
    Yeah - I asked someone on MSN and they told me what to do. I had an include on my pages for the header, but not the very top of the code :( dang! lol.
     
    crazyryan, Oct 16, 2006 IP
  7. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry about that, I sort of just threw something together. :)

    Glad you've got it working.
     
    streety, Oct 16, 2006 IP
  8. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #8
    Dude don't be sorry your script was great. Thanks again :)
     
    crazyryan, Oct 16, 2006 IP