[go: up one dir, main page]

0% found this document useful (0 votes)
33 views10 pages

PHP Programs

The document contains code snippets for several PHP programs including: 1. An Armstrong number checker that takes a user input number and determines if it is an Armstrong number. 2. A Fibonacci series generator that displays the Fibonacci series up to a user input limit. 3. A biodata form with inputs for personal details that submits to a second PHP page displaying the entered details. 4. A string reversal program that reverses a user input string. 5. A program that checks if a user input number is perfect, abundant or deficient based on the sum of its divisors. 6. A program demonstrating the use of cookies to track the last visit time of a user.

Uploaded by

Sreejith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views10 pages

PHP Programs

The document contains code snippets for several PHP programs including: 1. An Armstrong number checker that takes a user input number and determines if it is an Armstrong number. 2. A Fibonacci series generator that displays the Fibonacci series up to a user input limit. 3. A biodata form with inputs for personal details that submits to a second PHP page displaying the entered details. 4. A string reversal program that reverses a user input string. 5. A program that checks if a user input number is perfect, abundant or deficient based on the sum of its divisors. 6. A program demonstrating the use of cookies to track the last visit time of a user.

Uploaded by

Sreejith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

armstrong number

<html>
<body>
<h2>Find Armstrong Number</a></h2>
<form action=""method="post">
<input type="text"name="number"/>
<input type="submit"/>
</form>
<?php
if($_POST)
{
$number=$_POST['number'];
$temp=$number;
$sum=0;

while($temp!=0)
{
$rem=$temp%10;
$sum=$sum+($rem*$rem*$rem);
$temp=$temp/10;
}
if($number==$sum)
{
echo"$number is an Armstrong Number";
}
else
{
echo"$number is not an armstrong number";
}
}
?>
</body>
</html>

Fibonacci series

<html>

<head>

<title>Fibonacci Series</title>

</head>

<body>

<center><h2>Fibonacci Series</h2>

<form name="form" method="post">

<p> Enter the limit:

<input type="text" name="txtno"/>


</p></br>

</form>

</center>

</body>

<?php

if(isset($_POST['txtno']))

$n=$_POST['txtno'];

echo"<center><p><br>Fibonacci Series upto: ".$n."are"."<br>";

$a=-1;

$b=1;

for($i=1;$i<=$n;$i++)

$c=$a+$b;

if($c>=$n)

break;

echo "$c"."<br>";

$a=$b;

$b=$c;

?>

Biodata

Biodata1.php

<html>

<head>
<title>Biodata</title>

</head>

<body>

<center>

<form name="form1" action="biodata2.php" method="post">

<br><table>

<tr>

<td>

<label>Enter name:</label>

</td>

<td>

<input type="text" name="name"/>

</td>

</tr>

<tr>

<td>

<label>Enter Guardian's Name:</label>

</td>

<td>

<input type="text" name="guardian"/>

</td>

</tr>

<tr>

<td>

<label>Enter Gender:</label>

</td>

<td>
<input type="radio" name="gender" value="female"/>Female

<input type="radio" name="gender" value="male"/>Male

</td>

</tr>

<tr>

<td>

<label>Enter Date of Birth:</label>

</td>

<td>

<input type="text" name="dob"/>

</td>

</tr>

<tr>

<td>

<label>Enter Qualification:</label>

</td>

<td>

<input type="text" name="qualification"/>

</td>

</tr>

<tr>

<td>

<label>Enter Experience</label>

</td>

<td>

<input type="text" name="experience"/>

</td>
</tr>

<tr>

<td>

<label>Enter e-mail ID</label>

</td>

<td>

<input type="text" name="emailid"/>

</td>

</tr>

<tr>

<td>

<label>Enter contact number:</label>

</td>

<td>

<input type="text" name="mobno"/>

</td>

</tr>

<tr>

<td>

</label>

</td>

<td>

<input type="submit" name="submit" value="submit"?>

</td>

</tr>

</table>

</form>
</body>

</html>

Biodata2.php

<?php

$name=$_POST['name'];

$gname=$_POST['guardian'];

$gender=$_POST['gender'];

$dob=$_POST['dob'];

$qualification=$_POST['qualification'];

$experience=$_POST['experience'];

$emailid=$_POST['emailid'];

$mobno=$_POST['mobno'];

echo "<html>

<body>

<h1><u><center>Biodata</center></u></h1>

<table align='center' border='1'>

<tr>

<th>Name</th>

<td>$name</td>

</tr>

<tr>

<th>Guardian</th>

<td>$gname</td>

</tr>

<tr>
<th>Gender</th>

<td>$gender</td>

</tr>

<tr>

<th>DOB</th>

<td>$dob</td>

</tr>

<tr>

<th>Experience</th>

<td>$experience</td>

</tr>

<tr>

<th>Qualification</th>

<td>$qualification</td>

</tr>

<th>Email ID</th>

<td>$emailid</td>

</tr>

<tr>

<th>Mobile Number</th>

<td>$mobno</td>

</tr>

</body>

</html>"

?>

String reverse
<html>

<body>

<form action="" method="POST">

<H1>Reverse a string</h1>

Enter the string :

<input type="text" name="str" />

<input type="submit" />

</form>

</html>

<?php

if ($_POST) {

$string = $_POST["str"];

$len = strlen($string);

for ($i = ($len - 1); $i >= 0; $i--) {

echo $string[$i];

?>

Perfect
<html>

<head>

<title>PHP Program To Check a given number is Perfect , abundent or deficient</title>

</head>

<body>
<form method="post">

<table border="0">

<tr>

<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>

</tr>

<tr>

<td> <input type="submit" name="submit" value="Submit"/> </td>

</tr>

</table>

</form>

<?php

if(isset($_POST['submit']))

$n = $_POST['num'];

$r = 0;

$sum = 0;

for ($i = 1; $i <= ($n - 1); $i++)

$r = $n % $i;

if ($r == 0)

$sum = $sum + $i;

if ($sum == $n)

echo "$n is Perfect number.";


}

else if ($sum < $n)

echo "$n is Deficient number.";

else if ($sum > $n)

echo "$n is Abundant number.";

return 0;

?>

</body>

</html>

COOKIES
<?php

$timeframe=90*60*24*60*time();

setcookie('lastVisit',date("G:i-m/d/y"),$timeframe);

if(isset($_COOKIE['lastVisit']))

$v=$_COOKIE['lastVisit'];

else

echo "Welcome to our WebPage!";

echo "You have visited last time at:".$v;

?>

You might also like