View Full Version : php and background images

Jan 15, 2004, 01:01 PM
OK, based on recommendations from my other thread (this one (http://forums.macrumors.com/showthread.php?s=&threadid=55166)) I'm going to be adding a background image to my webpage. Piece of cake.

Here's the deal, I want to have it change the image randomly. No problem, if it was a standard html/php, I'd just do something like:
<img src="http://www.brianellisrules.com/background<?php rand(1,3);?>.jpg">
and let that go to town. I'm not 100% sure on the syntax, but basically that'd add a random number to the file name and then I'd have my random background, right? (assuming I have files named background1.jpg, background2.jpg, background3.jpg, etc) I think so.


That means I'd have to go to every single file and add that line to it. Not cool. With CSS you can handle that in one line, but I don't think you can put the php in there... can you? Is there a way around this? Help? Anyone? Beuller?


Jan 15, 2004, 01:32 PM
Do you have a separate file for your header? If so, you can dom something like defining your random variable at the top, and including just one style in the header, leaving the rest in your separate CSS file. Here is an example that changes the size of the text:

<? $num = rand(1,5); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta name="generator" content="BBEdit 7.1.1">
<link rel="stylesheet" href="allstyles.css" type="text/css">
<style type="text/css" media="all">
color: #003C73;
font-family: Verdana;
font-size: <?=$num?>em;


<div class="test">Woo Hoo!</div>

Jan 15, 2004, 01:45 PM
Yes I do....

I just tested it out, and it worked! Genius!