13 replies [Last post]
tommuir
Offline
Regular
Upper east side
Last seen: 13 years 29 weeks ago
Upper east side
Joined: 2004-04-05
Posts: 40
Points: 0

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.

i am not here

Tags:
Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 25 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Am I a bit slow?

Smile

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.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

seb
Offline
Enthusiast
Last seen: 13 years 23 weeks ago
Joined: 2003-09-20
Posts: 208
Points: 0

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.

seb
Offline
Enthusiast
Last seen: 13 years 23 weeks ago
Joined: 2003-09-20
Posts: 208
Points: 0

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.

roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 6 years 49 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

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.

Life's a b*tch and then you die!

seb
Offline
Enthusiast
Last seen: 13 years 23 weeks ago
Joined: 2003-09-20
Posts: 208
Points: 0

Am I a bit slow?

roytheboy wrote:
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.

roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 6 years 49 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

Am I a bit slow?

seb wrote:
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 Smile

Life's a b*tch and then you die!

seb
Offline
Enthusiast
Last seen: 13 years 23 weeks ago
Joined: 2003-09-20
Posts: 208
Points: 0

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.

roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 6 years 49 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

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 Laughing out loud :roll:

Life's a b*tch and then you die!

seb
Offline
Enthusiast
Last seen: 13 years 23 weeks ago
Joined: 2003-09-20
Posts: 208
Points: 0

Am I a bit slow?

Yeah, been a horribly busy day here.

seb
Offline
Enthusiast
Last seen: 13 years 23 weeks ago
Joined: 2003-09-20
Posts: 208
Points: 0

Am I a bit slow?

Roy, you'll be pleased to hear I have installed php5 and started relearning it Laughing out loud

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?

roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 6 years 49 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

Am I a bit slow?

...glad to hear it Cool

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' Wink

Life's a b*tch and then you die!

seb
Offline
Enthusiast
Last seen: 13 years 23 weeks ago
Joined: 2003-09-20
Posts: 208
Points: 0

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 Smile

roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 6 years 49 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

Am I a bit slow?

seb wrote:
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).

Life's a b*tch and then you die!