Simple PHP coding for dynamic images change by refresh the page

Hi,This is a dynamic images change by refresh the page .this is  randomly change image to refresh  page .simple code to change a  background and images and much more ,, using  rand(); rand(1,5); is  display 1 to 5 images to dynamic change of images,randomly .

Set  random number 

rand(); is used to set the number to change of image or content

$num = rand( 1,2 );

Set a image to randomly change 

Switch() is used to execute a one by one  it execute a  ture part one ...

switch( $num )
{

case 1: $image_file = "1.jpg";
break;
case 2: $image_file = "2.jpg";
break;
}
echo "<img src=
images/".$image_file." />";

Source Code:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP coding for random image dipaly to refresh apge</title>
</head>
<body>
<?php
srand( microtime() * 1000000 );
$num = rand( 1, 5 );
switch( $num )
{
case 1: $image_file = "1.jpg";
break;
case 2: $image_file = "2.jpg";
break;
case 3: $image_file = "3.jpg";
break;
case 4: $image_file = "4.jpg";
break;
case 5: $image_file = "5.jpg";
break;
}
echo "<img src=
images/".$image_file." />";
?>
</body>
</html>


No comments:

Post a Comment