Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Aperture

macrumors 68000
Original poster
Mar 19, 2006
1,876
0
PA
Hi. I am trying to embed this code into my page.

Code:
<?php 
$file_array = array
('http://www.kevinschaefer.net/home1.png'); 
$total = count($file_array); 
$random = (mt_rand()%$total); 
$file = "$file_array[$random]"; 
print("<img src=$file></a>");
?>

If you take a look at the page, there is a picture of a bench as the background.

How can I embed the PHP File into the code so the picture of the bench changes with each new visitior?

I uploaded the HTML/PHP file onto my server. If you could take a look at the Page Source, it would be greatly appreciated.


Please, I've tried everything.

Kevin
 
test.html gives me a 404.

Most web servers are configured to parse PHP code in .php pages only, so if you're sticking your code into a .html file, this is the first reason it might not be working.

You also have a comma after your sole array element.

I would suggest, if the bench (or whatever random picture shows up) is a background, to make the PHP spit out the appropriate image in a <style> block in the <head>

ie:

HTML:
<head>
<title>Whee!</title>
<!-- css file links -->
<style type="text/css">
<!--
.content {
background-image: url('<?php

$file_array = array(
'http://www.kevinschaefer.net/home_bench.png',
'http://www.kevinschaefer.net/home_monkies.png'
); 

$total = count($file_array); 

$random = ( mt_rand() % $total ); 

$file = $file_array[$random]; //you don't need quotes!
echo $file;

?>');
}
-->
</style>
</head>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.