Go Back   SitePoint Forums > Forum Index > Design Your Site > Web Page Design > CSS
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Oct 31, 2004, 18:06   #1
ArticleBot
SitePoint Articles
 
ArticleBot's Avatar
 
Join Date: Apr 2001
Posts: 0
Article Discussion

This is an article discussion thread for discussing the SitePoint article, "Build A Simple Style Switcher in CSS"
ArticleBot is offline   Reply With Quote
Old Oct 31, 2004, 18:06   #2
Icheb
SitePoint Wizard
 
Icheb's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 1,495
Why does everyone feel the need to use something like

$theStyle = $HTTP_GET_VARS["style"];

and then use the newly defined variable in the script, instead of just going ahead with $HTTP_GET_VARS["style"] when it's clear that the variable's content is unlikely to change anyways?
Icheb is offline   Reply With Quote
Old Oct 31, 2004, 18:18   #3
Pace Thug
SitePoint Member
 
Join Date: Mar 2004
Location: Växjö, Sweden
Posts: 10
As I am using cache on many of my pages this tip isn't very useful. Two different users ending up looking at my front page with a cache of a third users style is not an alternative.

You could probably solve it by importing a script instead of pure css:

Code:
@import url(page-that-produces-user-specific-css.aspx)
If there is no cookie, output the default style. Otherwise, output the customizations.
Pace Thug is offline   Reply With Quote
Old Oct 31, 2004, 19:10   #4
charmedlover
Floridian Opera Brigadier
 
charmedlover's Avatar
 
Join Date: Jul 2004
Location: Florida
Posts: 1,974
I used a similar system although it relied on sessions and was based on the users prefrences set in their acccount (you had to register). This method looks cool and I may use it on my other site. Nice article!
charmedlover is offline   Reply With Quote
Old Oct 31, 2004, 20:02   #5
Eric.Coleman
Ribbit...
 
Eric.Coleman's Avatar
 
Join Date: Jun 2001
Location: In your basement
Posts: 1,373
Couple of errors...

$HTTP_GET_VARS should be $_GET

$HTTP_REFERER should be $_SERVER['HTTP_REFERER']

You should be using the new globals, the old styles were dropped with php 4.1, and PHP 5 doesn't set the HTTP_*_VARS anymore.

- Eric
Eric.Coleman is offline   Reply With Quote
Old Oct 31, 2004, 21:15   #6
Bryce
SitePoint Enthusiast
 
Bryce's Avatar
 
Join Date: Sep 2003
Location: Perth, Western Australia
Posts: 48
This is a handy article, although I don't understand the use of the case statement for setting $styleCookie var.

Is it saying that if $styleCookie is 'white' or 'orange' then do nothing, and if $styleCookie is green or empty set $styleCookie to default? If so, why was the case statement used here over an IF statement?
Bryce is offline   Reply With Quote
Old Oct 31, 2004, 23:11   #7
Pony99CA
SitePoint Member
 
Join Date: Oct 2004
Location: Hollister, CA
Posts: 5
My Way

Quote:
Originally Posted by ArticleBot
This is an article discussion thread for discussing the SitePoint article, "Build A Simple Style Switcher in CSS"
I did this using JavaScript on my site (I didn't have access to server-side scripting, and why bother wasting time on the server when I can have the client do this?). See my Preferences page for an example.

I even have a preview window and separated the style sheet and font size settings.

Steve
Pony99CA is offline   Reply With Quote
Old Oct 31, 2004, 23:24   #8
Pony99CA
SitePoint Member
 
Join Date: Oct 2004
Location: Hollister, CA
Posts: 5
Quote:
Originally Posted by Bryce
This is a handy article, although I don't understand the use of the case statement for setting $styleCookie var.

Is it saying that if $styleCookie is 'white' or 'orange' then do nothing, and if $styleCookie is green or empty set $styleCookie to default? If so, why was the case statement used here over an IF statement?
It could use an IF statement like the following:

if (($styleCookie == "green") || ($styleCookie == "")) {
$styleCookie = "default";
}

(If PHP doesn't look like C, fix the syntax as needed.)

Of course, if your cookie values don't exactly match the names of the stylesheets, using a switch statement will be better than trying to list multiple alternatives in one branch of the IF statement.

Steve
Pony99CA is offline   Reply With Quote
Old Oct 31, 2004, 23:51   #9
ranvier
SitePoint Enthusiast
 
ranvier's Avatar
 
Join Date: Oct 2004
Location: Singapore
Posts: 25
Interesting article and are simple to digest although there are already a substantial amount of similar tutorials on CSS stylechanging.

But nevertheless, keep up the good work man! :)
ranvier is offline   Reply With Quote
Old Nov 1, 2004, 04:01   #10
Edora
Business Growth *******s, Inc
 
Edora's Avatar
 
Join Date: Oct 2004
Location: The Netherlands
Posts: 798
Certainly a good article/tutorial for every webmaster. Css is the new way of designing these days, and every example can make readers learn a lot.
Edora is offline   Reply With Quote
Old Nov 1, 2004, 04:58   #11
cranial-bore
SitePoint Wizard
 
cranial-bore's Avatar
 
Join Date: Jan 2002
Location: Australia
Posts: 2,092
...or if you were hell bent on keeping the file sizes of cookies small and you had a significant quantity of user preferences you could assign visitors a unique ID, store that in a cookie on their side, in a database table on your side and keep all the settings in the database.

This would also allow you to see which settings were more popular, and also store non-css preferences for users.
cranial-bore is offline   Reply With Quote
Old Nov 1, 2004, 06:12   #12
Bryce
SitePoint Enthusiast
 
Bryce's Avatar
 
Join Date: Sep 2003
Location: Perth, Western Australia
Posts: 48
Quote:
Originally Posted by cranial-bore
...or if you were hell bent on keeping the file sizes of cookies small and you had a significant quantity of user preferences you could assign visitors a unique ID, store that in a cookie on their side, in a database table on your side and keep all the settings in the database.

This would also allow you to see which settings were more popular, and also store non-css preferences for users.
This is a nice spin to put on the tutorial - now that you've given me the idea, that's probably how I'm going to run my styles on the blog I'm currently designing.

Pony: thanks for the clarification
Bryce is offline   Reply With Quote
Old Nov 1, 2004, 08:08   #13
DarkAngelBGE
SitePoint Wizard
 
Join Date: May 2003
Location: Berlin, Germany
Posts: 1,818
The author should abide by the new php standards though. $HTTP_COOKIE_VARS and $HTTP_GET_VARS certainly aren't. It's $_GET and $_COOKIE.

Other than that good tutorial.
DarkAngelBGE is offline   Reply With Quote
Old Nov 1, 2004, 09:39   #14
syscrash
SitePoint Community Guest
 
Posts: n/a
Just a quick question to DarkAngel or anyone else who can answer this. Where can I find the new standards for PHP. I'm returning back into programming after being away for quite some time and want to see what I missed.
  Reply With Quote
Old Nov 1, 2004, 11:09   #15
jgoddard
SitePoint Enthusiast
 
Join Date: Nov 2003
Location: canada
Posts: 62
You can do this entirely in Javascript, with no need for server side code, and an extra trip to the server.
jgoddard is offline   Reply With Quote
Old Nov 1, 2004, 14:23   #16
Eric.Coleman
Ribbit...
 
Eric.Coleman's Avatar
 
Join Date: Jun 2001
Location: In your basement
Posts: 1,373
Read the PHP manual...

And DarkAngelBGE, I posted that same message up there around post number 4
Eric.Coleman is offline   Reply With Quote
Old Nov 2, 2004, 00:04   #17
saumendra
SitePoint Member
 
Join Date: Apr 2004
Location: india
Posts: 1
The Article talks very well about the amalgumation of Server side and Client side approach.
saumendra is offline   Reply With Quote
Old Nov 2, 2004, 02:47   #18
lveale
SitePoint Addict
 
lveale's Avatar
 
Join Date: Jun 2001
Location: Dublin
Posts: 223
Red face

Author here, will try to answer any queries thus far...

With regard to PHP standards, yes, should have used $_GET and $_COOKIE but my host doesn't support them so I cut and paste my code rather than editing it to reflect the newer standards that the rest of you may be using so apologies for that.

Bryce, in answer to your question,
This is a handy article, although I don't understand the use of the case statement for setting $styleCookie var.

Is it saying that if $styleCookie is 'white' or 'orange' then do nothing, and if $styleCookie is green or empty set $styleCookie to default? If so, why was the case statement used here over an IF statement?


The switch/case may be a bit unwieldy. If the variable is white or orange, then we don't need to do anything as the variable name will match the name of the CSS file i.e. white.css or orange.css. However, if we don't have a Cookie passed in (i.e. user hasn't bothered to choose), or green is passed in then we use the default.css, which happens to be green.


syscrash, recommend just going to the PHP site and searching the function list there. Sitepoint do a great book,which has recently been updated.

Hope that helps, at least the article has stimulated some discussion and feedback so I'm happy with that
lveale is offline   Reply With Quote
Old Nov 4, 2004, 12:37   #19
polvero
Google Engineer
 
polvero's Avatar
 
Join Date: Oct 2003
Location: Mountain View
Posts: 614
good stuff.
i like this method better (although not as swift) than the ala javascript styleswitcher. The neat thing about the javascript method is the fact that it switches the style right there on the page rather than requiring a page reload.
HOWEVER, this is much more reliable. Perhaps I'll allow my users to use both...
Thanks
polvero is offline   Reply With Quote
Old Nov 5, 2004, 16:37   #20
scattermachine
SitePoint Enthusiast
 
scattermachine's Avatar
 
Join Date: Sep 2004
Location: USA
Posts: 52
Preferential treatment

Great article, and a very interesting technique!

For anyone interested in a host that supports the new naming convention, I highly recommend:


http://www.12wonderhosting.com


scattermachine is offline   Reply With Quote
Old Nov 9, 2004, 17:05   #21
Pony99CA
SitePoint Member
 
Join Date: Oct 2004
Location: Hollister, CA
Posts: 5
It's Catching

Quote:
Originally Posted by Eric.Coleman
And DarkAngelBGE, I posted that same message up there around post number 4
It must be catching -- jgoddard said the same thing I said in post #7. Are duplicate post shots as hard to come by as flu shots?

Steve
Pony99CA is offline   Reply With Quote
Old Nov 10, 2004, 00:51   #22
wildsue
SitePoint Enthusiast
 
wildsue's Avatar
 
Join Date: Oct 2003
Location: Switzerland
Posts: 43
the idea with the default.css is super, it takes less time to change for default values. Next time I'll try it out!
wildsue is offline   Reply With Quote
Old Nov 10, 2004, 01:10   #23
Mike
SitePoint Community Guest
 
Posts: n/a
Perhaps a nicer way to handle the php would be:

<link rel="stylesheet" type="text/css" href="/style/<?= ($HTTP_COOKIE_VARS["style"]) ? $HTTP_COOKIE_VARS["style"]; : "default": ?>.css" media="screen" />\n";
  Reply With Quote
Old Nov 22, 2004, 18:42   #24
scott_sauyet
SitePoint Member
 
Join Date: Nov 2004
Location: Andover, CT, USA
Posts: 0
This all makes sense, and I've seen a few good implementations of it around the web. But one thing doesn't make sense to me. Why in the world would you do a CSS "@import" and take the additional server hit when you could simply serve the CSS via PHP and do an "include" instead?
scott_sauyet is offline   Reply With Quote
Old Mar 8, 2005, 09:37   #25
dave_
SitePoint Member
 
Join Date: Mar 2005
Posts: 0
i tried this out, i could get the cookie to work and the change of style, but not the header, heres what i tried:

<?php
$theStyle = $HTTP_GET_VARS['style']; /* querystring */
setcookie("style", $theStyle, time()+36000, "/", "");
header("Location: $HTTP_SERVER_VARS[HTTP_REFERER]");
exit;
?>

if i comment out the header line then the cookie works but i have to hit back and refresh, if i leave it in then the header line works and the cookie doesnt
dave_ is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 13:30.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved