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
https://forums.phpfreaks.com/topic/29820-change-css-values-for-website/
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"/>
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.