Jump to content

Fopen + css


sevin

Recommended Posts

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_all

http://hacktheroot.com is where it will be
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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..
Link to comment
Share on other sites

[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.
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.