Updated - PHP Programs
Updated - PHP Programs
Updated - PHP Programs
File: display.php
<html>
<head>
<title>ColorDisplay</title>
</head>
<body>
<h2>An Interactive PHP Color Sampler</h2>
<?php
// get input values
$r = $_GET['r'];
$g = $_GET['g'];
$b = $_GET['b'];
// generate RGB string from input
$rgb = $r . ',' . $g . ',' . $b;
?>
R: <?php echo $r; ?><br>
G: <?php echo $g; ?><br>
B: <?php echo $b; ?>
<p />
<div style="width:150px; height: 150px;
background-color: rgb(<?php echo $rgb; ?>)" />
</body>
</html>
2. Write a PHP program to read height and weight. Compute and print Body Mass Index (BMI).
Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult
men and women.
BMI Categories:
Underweight = <18.5
Normal weight = 18.5–24.9
Overweight = 25–29.9
Obesity = BMI of 30 or greater
File: bmi.php
<html>
<head>
<title>BMI Calculator</title>
</head>
<body>
<h1 align="center">Body Mass Index Calculator</h1>
File:bmicalc.php
<?php
$val1= $_POST["weight"];
$val2= $_POST["height"];
$val3= $val2*$val2;
$mainval=$val1 / $val3;
$bmi=substr($mainval,0,4);
?>
<h2 align="center">Body Mass Index Calculator</h2>
<h2 align="center"><?=" Your BMI value is=". $bmi ?></h2>
<?php
if($bmi<=18.5){
?>
<h2 align="center">Oops!! you are Underwieght</h2>
<?php
}elseif($bmi>18.5 && $bmi<25){
?>
<h2 align="center">Ooh!! you are FIT</h2>
<?php
}elseif($bmi>25 && $bmi<30){
?>
<h2 align="center">Oops!! you are Overwieght</h2>
<?php
} else {
?>
<h2 align="center">Oops!! you have Obessity</h2>
<?php
}
?>
3. Write a PHP program to print factorial of a given number.
File: Fact.php
<html lang>
<head>
<title>Factorial</title>
</head>
<body>
<form align="center" action="Fact.php" method="post">
<h1 align="center">Factorial of a number</h1>
<h3> Enter a Number :<br>
<input type="number" name="num" ><br>
<input type="Submit" name="Submit"></h3>
</form>
</body>
</html>
<?php
$num=$_POST["num"];
$fact=1;
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$prime_nums=array();
echo "<br> <br>";
echo "<h2 align='center'> Prime numbers from " . $num1 . " to ". $num2 . " are : ";
function prime($num1, $num2){
$x= $num1;
while ($num1 <=$num2){
$isprime=true;
for($i=2; $i<= $num1/2; ++$i){
if($num1%$i==0){
$isprime=false;
break;
}
}
if($isprime==true){
$prime_nums[] = $num1 ;
}
++$num1;
}
$count= count($prime_nums);
foreach($prime_nums as $prime){
echo $prime . ", ";
}
echo "<br align='center'>There are " . $count ." number of prime numbers from " . $x . " to " .
$num2 ;
}
prime($num1, $num2);
?>
6. Write a program to validate user credentials. HTML Login page with username and password
fields and PHP program to validate the credentials stored in an array.
File: login.php
<?php
File: logout.php
<?php
header("location:login.php"); /* Redirect to login page */
exit;
?>