View Full Version : PHP random backrground
mlk
April 20th, 2003, 02:40 PM
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>
ahmed
April 20th, 2003, 03:06 PM
what erroe message does it give ya? try
<?php echo(rand(1,4)); ?>
ahmed
April 20th, 2003, 03:11 PM
oh.. and i would rather use a client-side languae for simple thing like these :)
mlk
April 20th, 2003, 03:19 PM
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...
ahmed
April 20th, 2003, 03:26 PM
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 :)
http://24.141.60.208/ran.php
nobody
April 20th, 2003, 03:49 PM
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.
mlk
April 20th, 2003, 05:22 PM
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....
nobody
April 20th, 2003, 05:27 PM
oh.. sorry, i didnt read the thread to well
good luck to ya
Jubba
April 20th, 2003, 06:46 PM
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
ahmed
April 20th, 2003, 06:55 PM
hmm.. i used the exact script i posted about and it does generate a random number.. i didnt 'initialize' it :)
Jubba
April 20th, 2003, 06:58 PM
its only the older versions. His server might be behind.. just a probable suggestion. :)
mlk
April 20th, 2003, 07:10 PM
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.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.