Jump to content

[SOLVED] PHP style swticher- again!


coalduststar

Recommended Posts

Hi - i've read the other posts deal with this and tried to apply the solutions but they don't work and i'm ready to go schitzo so any help would be pretty good right now

 

I was using the ALA php style switcher but that was an abject disaster: http://www.alistapart.com/articles/phpswitch/ and now i'm trying to implement this one http://gr0w.com/articles/code/css_stylesheet_switcher_using_php_javascript_free/.

 

Suffice to say I feel like an ass but i remember reading on previous posts that there could be a problem with using localhost which is what i'm using- please advise.

 

OK- so i have an include that calls an array for the style sheets:

 

<?
$styleSheets = array();

// DEFINE STYLESHEETS
$styleSheets[0]["text"]='std';
$styleSheets[0]["title"]='std';
$styleSheets[0]["sheet"]='<link href="../css/newlayout_css.css" rel="stylesheet" type="text/css" />';

$styleSheets[1]["text"]='big';
$styleSheets[1]["title"]='bigtext';
$styleSheets[1]["sheet"]='<link href="../css/newlayout_css_bigtext.css" rel="stylesheet" type="text/css" />';

// DEFAULT STYLESHEET
$defaultStyleSheet=0;

// SET STYLESHEET
if(!isset($_COOKIE["STYLE"])){
if(isset($_SESSION["STYLE"])){
  echo $styleSheets[$_SESSION["STYLE"]]["sheet"];
}else{
  echo $styleSheets[$defaultStyleSheet]["sheet"];
}
}else{
echo $styleSheets[$_COOKIE["STYLE"]]["sheet"];
}
?>

 

And here's the code for the cookie:

 

<?
// SET COOKIE FOR 1 YEAR
if(isset($_REQUEST["SETSTYLE"])){
if(setcookie("testcookie",true)){
  setcookie("STYLE",$_REQUEST["SETSTYLE"],time()+31622400, "/");
}else{
  $_SESSION["STYLE"]=$_REQUEST["SETSTYLE"];
}
}
// RETURN TO CALLER PAGE
header("Location: ".$_SERVER["HTTP_REFERER"]);
?>

 

Do I need to put in the domain or anything in here or is it ok to leave "testcookie" as a name?

And finally the link, calling the switcher:

 

  
<?
// WRITE OUT SWITCHER LINKS
while(list($key, $val) = each($styleSheets)){
echo "<a href='styleswitcher.php?SETSTYLE=".$key."' title='".$val["title"]."'>".$val["text"]."</a>";
}
?>

 

Have I not defined something? I'm a php butcher basically, I try and pick it up as I go along and am relatively competent in doing simple stuff like getting data out of tables for web sites as I'm a web/graphic designer but this has pissed me right off- both tutorials I've looked at seem simple and easy to implement- could someone let me know what i've screwed up?

Link to comment
Share on other sites

i'm a dick by the way.

 

i had my stylesheets listed like this:

 

<link rel="stylesheet" type="text/css" media="screen" title="std" href="../css/newlayout_css.css" />
<link rel="alternate stylesheet" type="text/css" media="screen" title="bigtext" href="../css/newlayout_css_bigtext.css" />
<link rel="alternate stylesheet" type="text/css" media="screen" title="lexic" href="../css/newlayout_css_lexic.css" />

 

so it was just staying on the one sheet- i've changed it so that all my listed css is alternate stylesheets:

 

<link rel="alternate stylesheet" type="text/css" media="screen" title="std" href="../css/newlayout_css.css" />
<link rel="alternate stylesheet" type="text/css" media="screen" title="bigtext" href="../css/newlayout_css_bigtext.css" />
<link rel="alternate stylesheet" type="text/css" media="screen" title="lexic" href="../css/newlayout_css_lexic.css" />

 

sorry if i wasted anyone's time

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.