Jump to content

CSS BackGround From PHP Random Image Script


woocha

Recommended Posts

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

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

Archived

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

×
×
  • 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.