HTML/PHP Help

Discussion in 'Web Design and Development' started by Aperture, Oct 23, 2006.

  1. Aperture macrumors 68000

    Aperture

    Joined:
    Mar 19, 2006
    Location:
    PA
    #1
    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
     
  2. NoNameBrand macrumors 6502

    Joined:
    Nov 17, 2005
    Location:
    Halifax, Canada
    #2
    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>
    
     

Share This Page