tfurnivall Posted February 28, 2006 Share Posted February 28, 2006 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 ;-) Quote Link to comment https://forums.phpfreaks.com/topic/3786-changing-background-color-under-php-control/ Share on other sites More sharing options...
TylerL Posted March 9, 2006 Share Posted March 9, 2006 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. :) Quote Link to comment https://forums.phpfreaks.com/topic/3786-changing-background-color-under-php-control/#findComment-15628 Share on other sites More sharing options...
thecolor Posted October 12, 2007 Share Posted October 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/3786-changing-background-color-under-php-control/#findComment-368253 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.