woocha Posted June 24, 2008 Share Posted June 24, 2008 Hi Guys... I ran into a problem today. I am designing a new site and my background image is show in my style sheet. I need to know if I can throw php in a .css file to execute a php random image function. The idea is to display a new image at random on a refresh or new visit. So can I do this, or does anyone know of a different or maybe better way? Thanks Guys Link to comment https://forums.phpfreaks.com/topic/111668-css-background-from-php-random-image-script/ Share on other sites More sharing options...
nashruddin Posted June 24, 2008 Share Posted June 24, 2008 It's possible. but the 'dynamic' CSS should reside at the HTML page (not in a separate file). Maybe something like this: <?php /* this function selects random image and returns its URL */ function get_random_img() { /* ...some code here... */ } ?> <html> <head> <style type="text/css"> @import url('style.css'); body { background: url('<?php echo get_random_img() ?>'); } </style> </head> ... Link to comment https://forums.phpfreaks.com/topic/111668-css-background-from-php-random-image-script/#findComment-573385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.