PHP random backrground

could someone help me with a bit of php code ???

im trying to generate 4 different backgrnds in php
in my directorie are 4 jpg named 1,2,3 and 4
why doesnt this work:


<html>
<body background="<?php echo rand(1,4) ?>.jpg">
</body>
</html>

what erroe message does it give ya? try

<?php echo(rand(1,4)); ?>

oh… and i would rather use a client-side languae for simple thing like these :slight_smile:

problem is i dont think java would be capable of editing the background image - maybe I should check…
Your code does the same thing mine did:
http://mlkdesign.free.fr/php/tryout2.php3

It only displays the file named 1.jpg…

this file has the same script i posted above, it does print a random number between 1 and 4… besides javascript IS capable of doing this, search the forums :slight_smile:

http://24.141.60.208/ran.php

I have a javascript code that puts a random image in a page, i don;t know how you would do it for a background, but if u want, i could give u the code.

i know the code for the image, and the php script does work for a normal image, it’s just that it wont work with the background, i have no clue why.
Ill try to post this on a specialised php phorum…

oh… sorry, i didnt read the thread to well
good luck to ya

you have to enable the random function for php… hold on let me find it…

you have to use srand() to initialize the random-ness in php.

http://www.php.net/manual/en/function.srand.php

hmm… i used the exact script i posted about and it does generate a random number… i didnt ‘initialize’ it :slight_smile:

its only the older versions. His server might be behind… just a probable suggestion. :slight_smile:

my server allows php4 and all that. i dont think it is way behind… What I might do is try to generate a random CSS background in php and see if it works…

What I need now is some sleep.