Jump to content

Archived

This topic is now archived and is closed to further replies.

tfurnivall

Changing background color under PHP control

Recommended Posts

I'd like to use PHP to change a CSS 'background color' rule based on the date. I guess that every time the CSS page is referenced, I could go through the calculation of what color to use, but this would get real old, real fast! (This is a determination of the appropriate liturgical color, and involves getting the date of Easter for the current year, and then figuring our whereabouts in the Church calendar we happen to be).

Things get slightly more complex because the seasons have some options (Advent can be Purple or Blue, for example).

Any ideas about how I can accomplish this? I'm thinking that the following might work:

i) Establish a session variable called liturgical_color, and then use a short script to put it into a style sheet in among all the other style commands:

ii) <?php echo "background-color:".$_SESSION['liturgical_color']".";"; ?>

My question:

Do browsers (or most browsers?) handle css directives out of a php script?

Any help gratefully appreciated!

Tony (What ever happened to COBOL ;-)

Share this post


Link to post
Share on other sites
PHP is generated BEFORE everything and is done on the server side, thats why you dont see any PHP code or anything when it is generated in pure HTML... Therefore, the example you gave is correct, for the most part, in that that will select which color to use in terms of the date, you may want to run something that checks to see if its any certain date, and if so set it to that color, if it isnt, set it to the default color and print it that way.

This is how most sites have different modules that allow for color changes, they simple have a thing like:

echo $background["color"];

Where $background is a query into a database of the different possible colors and usernames...it then picks out their color selection and replaces all the coding you did with the word "brown" thus making the background color brown for that selected user. :)

Share this post


Link to post
Share on other sites
I've looked a bit over the forum for a similar function.  Unfortunately I'm not so strong at PHP (basics)... and am trying to make a table background color change based on the time of day.

Like the iGoogle background that changes based on your zip code for weather and such,  I'd like to be able to capture the time the user visiting is in (wherever in the world) and display a background color related to the time of day.  (i.e. black for darkness and yellow for noon or similar.).

Any help would be greatly appreciated.

Thanks,
~TC

Share this post


Link to post
Share on other sites

×

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.