Jump to content

Changing background color under PHP control


tfurnivall

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

Link to comment
Share on other sites

  • 2 weeks later...
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. :)
Link to comment
Share on other sites

  • 1 year later...
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.