CSS BackGround From PHP Random Image Script

Discussion in 'CSS' started by woocha, Jun 24, 2008.

  1. #1
    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
     
    woocha, Jun 24, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    You can use a php script to output valid CSS. So yes. The link would have to be say style.php and php would do its processing part then output the CSS.
     
    shallowink, Jun 24, 2008 IP
  3. woocha

    woocha Peon

    Messages:
    107
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    great thanks so much :)

    so the css would be be:
    
    body 
    {
    background-image: url('style.php');
    }
    
    
    Code (markup):
    Then have the PHP script return the jpg value
    Is that what you are saying?
    Thanks
     
    woocha, Jun 24, 2008 IP
  4. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #4
    no, the link from the main page would be to style.php. Though there isn't anything stopping you from doing it the way you listed, it should work. I know it works with the img tag. Just haven't bothered to do it

    link rel="stylesheet" href="style.php" ... blah ... blah

    then style.php would do the processing

    if($mode=="alpha") {

    echo " body
    {
    background-image: url('style.php');
    }":
    else { .... }

    then the rest of the style sheet.
     
    shallowink, Jun 24, 2008 IP