Well... I just found out you could reference *.php files as css...
<html> <head> <link rel="stylesheet" type="text/css" href="css.php"> </head> <body> </body> </html>
<?php echo "body{background-color: blue;}"; ?>
Did you guys already know that, 'cause it's new to me.
Am I a bit slow?
http://www.csscreator.com/css-forum/ftopic4047.html&highlight=php+variables
Never seen a reason for this before but working on a large stylesheet and trying to find every instance of a color when you want to update
does become a pain, seems like a neat idea to have colors declared as a group of variables! may well give it a go.
Hugo.
Am I a bit slow?
When I initially started in CSS I came across this issue - I had several colours I wanted to keep the same. So I saved my css files as asp, and put a variable or two in.
Not entirely sure why I stopped doing it, I think there was a good reason....
It may have been something as incidental as my editor not colourcoding my files correctly, which isn't a big concern, and can be worked around.
Am I a bit slow?
Implemented this myself last night, in an ASP file.
[link removed]
(two style switchers in the footer bar). Clicking on one changes the style and sets a cookie so the site remembers how you'd set it.
/css/main.asp
<%response.contentType = "text/css"%> <%response.expires = -1442%> @import url("undohtml.css"); <% dim sBodyBGColor dim sHrefLVColor dim sHrefHAColor dim sContBGColor dim sFootBGColor dim sBasicFont dim c : c = request.cookies("styles")("colours") select case c case 2: sBodyBGColor = "#300" sHrefLVColor = "#900" sHrefHAColor = "#300" sContBGColor = "#ecc" sFootBGColor = "#966" case 3: sBodyBGColor = "#030" sHrefLVColor = "#070" sHrefHAColor = "#030" sContBGColor = "#cec" sFootBGColor = "#696" case 4: sBodyBGColor = "#003" sHrefLVColor = "#009" sHrefHAColor = "#003" sContBGColor = "#cce" sFootBGColor = "#669" case else: sBodyBGColor = "#333" sHrefLVColor = "#666" sHrefHAColor = "#000" sContBGColor = "#eee" sFootBGColor = "#999" end select dim f : f = request.cookies("styles")("fonts") select case f case 2: sBasicFont = "Verdana, Helvetica, Arial, sans-serif" case else: sBasicFont = """Palatino Linotype"", Georgia, ""Times New Roman"", serif" end select%> /* filename: main.css description: after killing everything with undohtml.css, we set styles to apply to the entire site in this file version: 1.00 author: Seb Frost (http://www.sebfrost.co.uk) */ body { font-family: <%=sBasicFont%>; text-align: center; background: <%=sBodyBGColor%>; padding: 5% 0 2%; font-size: 76%;} etc etc...
The -1442 on the expires property specifys 60min * 24hr + 2 (rounding) to ensure that wherever in the world the user is in relation to the server the CSS will have expired.
This does incur the hit that the CSS is reloaded with every page, instead of being cached - can anyone see a good way of getting around that?
interestingly, without the expiry set, Firefox and IE5.5/6 still worked fine, but IE5 and Opera required refreshing the page to get it to see the new styles.
Am I a bit slow?
If I want to change the odd CSS attribute on the fly, I write (with php obviously) those specific bits of CSS into the head of the document so that they overrule the linked stylesheet. It keeps things simple (the way I like it).
If I want to change stylesheets then I simply change the link on the fly with php (obviously).
If I then want to track such a change because the user has selected it, I assign a URL variable to carry the setting from page to page throughout the site e.g. www.website.com/page.php/1 where one is the variable. In simpler terms this could also be www.website.com/page.php&setting=1 but that's not as neat or SE friendly.
This may not be as refined as using cookies but as a php fan, it's very easy for me to get to grips with.
Am I a bit slow?
This may not be as refined as using cookies but as a php fan, it's very easy for me to get to grips with.
Well cookies aren't complicated, this is the code that gets executed when you click on one of the aforementioned links on my dev site:
<%if request.querystring("c")<>"" then response.cookies("styles")("colours") = request.querystring("c") response.cookies("styles").expires = date + 365 end if%> <%if request.querystring("f")<>"" then response.cookies("styles")("fonts") = request.querystring("f") response.cookies("styles").expires = date + 365 end if%> <%response.redirect(request.servervariables("http_referer"))%>
I don't recall how to do the same in PHP, but it's not going to be more than a line or two of code, and saves you passing the style settings in the URL.
Additionally, before I embarked on this experiment I was using javascript switchable stylesheets. I've adopted this method for a couple of reasons:
1) no reliance on the user having javascript enabled (though that's almost a given)
2) easier style sheet maintenance. With simple changes like this all I want to change is a few colours. With a non-dynamic stylesheet I'd have to either
a) split the sheet into one "base" sheet and then lots of small ones to control fonts/colours.
b) keep several copies of a stylesheet that are 90% identical and require duplicated work when I change something.
Am I a bit slow?
Well cookies aren't complicated
I know they're not, but for a while now I've been coding things to work without reliance on cookies and that to me is just as important as working without javascript and flash etc. Cookies got a huge amount of bad press a while back and what with recent european legislation and IE now going from one security extreme to the other ( ](*,) ), it simply makes sense to me to move away from cookies. This is difficult with ecommerce sites but I do this sort of thing and it works a treat:
if (isset($_GET["PHPSESSID"])) {
$passsid = "?PHPSESSID=".$_GET["PHPSESSID"];
} else {
$passsid = "";
}
header ("Location:foobar.php/123".$passsid);
exit;
In essence we're talking about the same thing here, I'm just sharing the way that I do things on the server, as simply as possible

Am I a bit slow?
I appreciate the problems with using cookies, realyl we should be using a combination of our methods. Yours for page-to-page passing of any settings if cookies aren't present, and mine so that if cookies are present then the user will be remembered when he comes back a week later.
Am I a bit slow?
Yes, I agree. It's interesting and useful, this discussion lark; just a shame that it stops me getting on with the huge backlog of work that I have :roll:
Am I a bit slow?
Yeah, been a horribly busy day here.
Am I a bit slow?
Roy, you'll be pleased to hear I have installed php5 and started relearning it
How do I convert my QS to slash-separated values like you showed? I know in ASP you have to install a 3rd party ISAPI filter, but I'm presuming it's built into PHP?
Am I a bit slow?
...glad to hear it
Generally speaking, you should find much more authoritive help and support on the web for php than asp and that should be reason enough to 'ditch the Micro$oft b*tch'
Am I a bit slow?
Well, unfortunately I work in a microsoft company, but there may be hp in our future here, or maybe I'll just fcuk them all off and go somewhere else - home ideally
Am I a bit slow?
How do I convert my QS to slash-separated values like you showed? I know in ASP you have to install a 3rd party ISAPI filter, but I'm presuming it's built into PHP?
There are various ways to do this depending upon the web server you're using and your access to the server. I use Apache's 'look back' feature, which is a very simple concept (the way I like things) but not very portable if your scripts are going to be used elsewhere. Google terms like 'php url "search engine friendly"'. I can't remember what I first read as I started doing this over a year ago but I've found these to get you started (I haven't read them):
http://www.zend.com/zend/spotlight/searchengine.php
http://www.sitepoint.com/article/search-engine-friendly-urls
http://www.webpronews.com/webdevelopment/sitedesign/wpn-26-20030606SearchEngineFriendlyPHPPages.html
If you use the look back feature you need to add ../ to all relative file paths in your script. The other thing that tripped me up for a while was when I upgraded one of my servers to Apache 2: the look back feature is off by default in 2 and has to be enabled in the config file, either globally or by vhost (then restart the httpd).