<html>
<?php
$song=rand(1,2);
if($song==1)
{
 echo "1.ram";
  }
else if($song==2)
  {
 echo "2.ram";
?>
<embed src="<?php echo ($song)?>" type="audio/x-pn-realaudio-plugin" WIDTH=0 HEIGHT=0 pluginspage="http://www.real.com/player/index.html?src=000629realhome" autostart="true" name="RealPlayer"></embed> 

</html>

WHy my codes don't work? I want it play randomly song?

    <html>
    <?php
    $name1 = "nbwo.ram";
    $name2 = "aika.ram";
    $name3 = "kilo.ram";
    $name4 = "nhaw.ram";
    ?>
    <embed src="<?php echo ($name.=rand(1,4); ?>" type="audio/x-pn-realaudio-plugin" WIDTH=0 HEIGHT=0 pluginspage="http://www.real.com/player/index.html?src=000629realhome" autostart="true" name="RealPlayer"></embed> 
    
    </html>
    

    this not work either.

      That's because you havent thought through what you are doing.

      1. $name has not been initialised.
      2. Even if it has, what good does rand() do?

      One way would be to place the filenames into an array:

      <html>
      <?php
      $name = array(
      	"nbwo.ram",
      	"aika.ram",
      	"kilo.ram",
      	"nhaw.ram"
      	);
      ?>
      <embed src="<?php echo $name[rand(0, count($name) - 1)]; ?>" type="audio/x-pn-realaudio-plugin" WIDTH=0 HEIGHT=0 pluginspage="http://www.real.com/player/index.html?src=000629realhome" autostart="true" name="RealPlayer"></embed>
      
      </html>
        Write a Reply...