PDA

View Full Version : HTML/PHP Help




Aperture
Oct 23, 2006, 05:53 PM
Hi. I am trying to embed this code into my page.

<?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 (http://www.kevinschaefer.net/test.html) onto my server. If you could take a look at the Page Source, it would be greatly appreciated.


Please, I've tried everything.

Kevin



NoNameBrand
Oct 23, 2006, 11:21 PM
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:


<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>