sevin Posted December 1, 2006 Share Posted December 1, 2006 Greetings, I am a decent PHP coder and I am experementing with a method of having alternating stylesheets via links that use fopen. Each link would change the color, ie red, blue, and default - green. the link would use fopen their coresponding css file and apply it in the document body. I have a sinking feeling it will involve preg_match_allhttp://hacktheroot.com is where it will be Quote Link to comment Share on other sites More sharing options...
projectshifter Posted December 1, 2006 Share Posted December 1, 2006 This really sounds like javascript would be a much better alternative. Otherwise you're going to want to store some kind of a cookie/session variable and use that to determine which one you're opening up, and it'll be a lot less dynamic than javascript would be. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 1, 2006 Share Posted December 1, 2006 Never rely on js!!!!!!!!!!There is no big deal switching between style sheets via server side scripting. So many ways to do it just take your pick and have a play. Although I would opt for something nice and simple like a session var and use that to pick which style sheet to use. Why would preg_match come into it? Just keep it nice and simple... Quote Link to comment Share on other sites More sharing options...
keeB Posted December 1, 2006 Share Posted December 1, 2006 [code=php:0]switch ($choice) { case "blue": $css = "blue.css" break; case "red": $css = "red.css" break; default: $css = "green.css";}[/code] Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 1, 2006 Share Posted December 1, 2006 I agree. A mixture of Javascript and [i]possibly[/i] PHP (depending on where you choose to store your user's settings) is the way to go on that. Typically, a cookie that simply holds the user's preferred style is all that's needed. You can do the same thing with things like font size selectors, too.Obviously, you never want to rely on this entirely. And, by that, I simply mean that you don't want to have anything on your site dependent on this. If it is something that will actually make a difference in their browsing experience (as far as what they can do), you may want to store their selection somewhere on the server. Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 1, 2006 Share Posted December 1, 2006 [quote author=ToonMariner link=topic=116994.msg477032#msg477032 date=1164988637]Never rely on js!!!!!!!!!![/quote]Why? For a style switcher, there is absolutely nothing wrong with using JS. In fact, that's typically the way it's handled when the selection doesn't do any more than change the layout look (not to mention being extremely easy to handle). IMHO, that's the preferred way to handle style switchers... in addition, what percentage of your users typically have JS disabled? Last check I ran, it's somewhere around 2%... hardly enough to worry about in most cases. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 1, 2006 Share Posted December 1, 2006 What if js is off but the user still would like to switch styles? By all means use it but never rely on it. You could construct your link like so...<a href="script.php?mode=switchstyle&colour=red" title="Swicth to red" onclick="return switchstyle(this.href);">Swicth to red</a>use js to extract the new color and do the switch. if js is off you script will know it should switch the style.. Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 1, 2006 Share Posted December 1, 2006 [quote author=ToonMariner link=topic=116994.msg477050#msg477050 date=1164989885]What if js is off but the user still would like to switch styles? By all means use it but never rely on it.[/quote]Again, I suppose this comes back to a preference thing, but I'm not going to spend the extra time to write the switcher twice (once in JS and once in PHP) just to accommodate a handful of users to be able to use a [b]feature[/b] that doesn't even really add to the experience of the page.Now, if there is something where you're offering entire [b]themes[/b], I'm of a different mindset entirely. I agree with you 100% there. You have to have a PHP backend to allow users to set themes that actually add to the experience. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.