Wednesday 9 April 2014

Random image display after refreshing page in PHP

This code will help you to change the background image of a page randomly after refreshing  page, using a function

i.e:- rand();

Here rand (1,5); is used to display 1 to 5 images dynamically changes when a user refresh the page
Here you can find the code please click below
DEMO
index.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Random image display after refreshing page using PHP</title>
</head>
<body>
<?php
srand( microtime() * 1000000 );
$num = rand( 1, 5 );
switch( $num )
{
case 1: $image_file = "ritu1.jpg";
break;
case 2: $image_file = "ritu2.jpg";
break;
case 3: $image_file = "ritu3.jpg";
break;
case 4: $image_file = "ritu4.png";
break;
case 5: $image_file = "ritu5.jpg";
break;
}
echo "<img src=images/".$image_file." />";
?>


</body>
</html>

No comments:

Post a Comment

Printing first 50 Fibonacci numbers Using PHP Program

Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. For example. 0 , 1 , 1 , 2 , 3 , 5...