Jump to content

change css values for website


rossh

Recommended Posts

Hi i'm trying to get a site working with different styles and i'm changing variables in one style.php file which was working fine, however every now and again the old style reappears on random pages?  Don't know if it's my conditional statements or a cache problem?  I have various areas on the site that are secure https and i had to add the domain for the cookie to work in the secure areas.  I could probably figure it out if the error was not random.  Also i'm guessing this is not the best solution if anyone can let me know the best way to go about this i would really appreciate it.

Thanks

R

Style.php

<?php
session_start();
header('Content-type: text/css');

if ($_SESSION['style'] == ""){
$logo = "../image/logo-purple.gif";
}else{
$logo = "../image/logo-".$_SESSION['style'].".gif";
}
if ($_SESSION['color'] == ""){
$color = "#9B83B7";
}else{
$color = $_SESSION['color'];
}
?>

header.php

  session_start();
require_once ("functions.php");
if ($_SESSION['style'] == ""){
$_SESSION['style'] = "purple";
}
if ($_COOKIE["style"] != ""){
$_SESSION['style'] = $_COOKIE["style"];
}
if(isset($_GET['style']) && $_GET['style']!=""){
$_SESSION['style'] = $_GET['style'];
}
setcookie ("style"); //Delete existing entry
setcookie('style', $_SESSION['style'], time() + (86400 * 30), '/', '.domain.com');  //.domain.com to deal with https

$style = $_SESSION['style'];

switch ($style){
case "purple":
  $_SESSION['color'] = "#9B83B7;";
  break;
case "green":
$_SESSION['color'] = "#8DC63F;";
break;
case "pink":
  $_SESSION['color'] = "#EC008C;";
  break;
case "orange":
  $_SESSION['color'] = "#F26521;";
  break;
case "brown":
  $_SESSION['color'] = "#726257;";
  break;
case "blue":
  $_SESSION['color'] = "#448CCB;";
  break;
case "print":
$_SESSION['color'] = "#000;";
break;
default:
  $_SESSION['color'] = "#9B83B7;";
}
Link to comment
Share on other sites

It could probably be done better if you created a few different CSS files and depending on which style needs to change just have the $_SESSION variable store the associated CSS file name which would change the following line in all your HTML documents

<link rel="stylesheet" type="text/css" href="some_theme.css"/>
Link to comment
Share on other sites

Hi thanks for getting back to me.  I did that originally but it was getting difficult to update if i needed to make changes to the stylesheet.  Any ideas why random pages whould revert to the previous style?  I've printed the session and cookie variables when this happens and they are the have the correct value but the wrong style?

Thanks

R
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.