Jump to content


Photo

Changing background color under PHP control


  • Please log in to reply
2 replies to this topic

#1 tfurnivall

tfurnivall
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 28 February 2006 - 11:03 PM

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 ;-)



#2 TylerL

TylerL
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 09 March 2006 - 12:20 AM

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

#3 thecolor

thecolor
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 October 2007 - 11:51 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users