Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll.

: 08

Assignment 1
1. Write a Program To Check Student Grade Based on The
Marks Using if else Statement.
 If Marks are 60% or More, Grade Will be First Division.
 If Marks Between 45% to 59%, Grade Will be Second Division.
 If Marks Between 33% to 44%, Grade Will be Third Division.
 If Marks re Less Than 33%, Student Will be Fail.

Ans. <html>
<head>
<title> Student Result </title>
</head>
<body>
<h1> Student Result Using if else. </h1>
<?php

$m1 = 70;
$m2 = 80;
$m3 = 91;
$m4 = 79;
$m5 = 67;
$t = $m1 + $m2 + $m3 + $m4 + $m5;
$p = $t / 500 * 100;

if ($p >= 60)


{
echo "Congratulation..!!! You have Pass With \"First Division\" Your Percentage Is ".
$p."%";
}
elseif ($p >= 45 & $p < 60)
{
echo "Congratulation..!!! You have Pass With \"Second Division\" Your Percentage Is ".
$p."%";
}
elseif ($p >= 33 & $p < 45)
{
echo "Congratulation..!!! You have Pass With \"Third Division\" Your Percentage Is ".
$p."%";
}
else

1
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

{
echo "Sorry... You Are Fail ".$p."%<br><br>\" Best Of Luck \" For Next Time.";
}
?>
</body>
</html>

Output :

2. Write a PHP Program Using Nested For Loop That Creates a


Chess Board.
 You can use html table having width=”400px” and take “30px” as cell
height and width for check boxes.

Ans. <html>
<head>
<title> Chess Board </title>
</head>
<body style="background-color: skyblue;">
<div>
<br>
<h2> Chess Board Create Using Nested For Loop. </h2>
<table width="400px" >
<?php
for ($i=0; $i < 8; $i++)
{
echo "<tr>";
for ($j=0; $j < 8 ; $j++)
{
$k=$i+$j;
if ($k%2==0)
{
echo "<td height=30px bgcolor=white></td>";
}

2
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

else
{
echo "<td width=30px bgcolor=black></td>";
}
}
}
?>
</table>
</div>
</body>
</html>

Output :

3. Write a simple calculator program in PHP using switch case.


(Addition, Subtraction, Multiplication and Division).

Ans. <html>
<head>
<title> switch case </title>
</head>
<body>
<h2> Addition, Subtration, Multiplication, Division Using Switch Case. </h2>
<?php
$a = 25;
$b = 14;
$c = "dvd";
switch($c)

3
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

{
case 'adc':
echo"Addition Of Two Number :-".($a+$b);
break;
case 'sub':
echo"Subtration Of Two Number :-".($a-$b);
break;
case 'mul':
echo"Multiplication Of Two Number :-".($a*$b);
break;
case 'dvd':
echo"Division Of Two Number :-".($a/$b);
break;
default;
echo"You Enterd Wrong.";
}
?>
</body>
</html>

Output :

4. Write a Program in PHP to Remove Specific Element by Value


From an array Using PHP Program.

 Take an array With List of Month Names.


 Take a Variable With The Name of Value to be Deleted.
 You can Use foreach Loop.

Ans. <html>
<head>
<title> Array</title>
</head>

4
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

<body>
<h2>Remove Specific Element By Value From an Array</h2>
<?php
$delete_item = 'April';
$months = array('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
'August',);
if (($key = array_search($delete_item, $months)) !== false)
{
unset($months[$key]);
}
var_dump($months);
?>
</body>
</html>

Output :

5. Write a PHP Function to Create a Human-Readable Random


String For a Captcha.

Ans. <html>
<head>
<title> Generate Random Captcha </title>
</head>
<h1> Generate Random Captcha </h1>
Captcha :
<?php
$a=rand(1,100);
$b=rand(1,100);
echo $a."+".$b;
if(isset($_POST['submit']))
{

5
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

$ar=$_REQUEST['ar'];
$n1=$_REQUEST['a'];
$n2=$_REQUEST['b'];
$t=$n1+$n2;
if($t==$ar)
{
echo "Your Captcha Is Correct. :)";
}
else
{
echo "Your Captcha Is Not Correct. :(";
}
}
?>
<body>
<form metod="post">
<input type="hidden" name="a" value="<?php $a ?>">
<input type="hidden" name="b" value="<?php $b ?>">
<input type="text" alt="ca" name="ar">
<input type="submit" class="b" alt="button" name="submit">
</form>
</body>
</html>

Output :

6. Write a PHP Program To Accept Data From User and Display


It on Another Page.

 User Input Should be First Name, Last Name, Address, Gender,


Phone No., Hobbies.

6
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

Ans. Regitsration Form


<html>
<head>
<title> Form </title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css2?
family=Kanit:wght@500&family=Oswald&display=swap" rel="stylesheet">
</head>
<style>
body{
background-image: linear-gradient(to right bottom, #e73bf8, #ff32c3, #ff4e98, #ff717a,
#ff8f6e, #f6a367, #e9b669, #dac775, #c2d783, #a5e59c, #84f1bf, #5ffbe6);
font-family: 'Kanit', sans-serif;
font-family: 'Oswald', sans-serif;
font-family: 'Roboto Condensed', sans-serif;
}
#input{
height: 50px;
width: 100%;
background-color: rgba(255,255,255,0.07);
border-radius: 10px;
padding: 0 10px;
margin-top: 8px;
font-size: 14px;
font-weight: 300;
color:white;
}
.b1{
width: 60%;
height: 40px;
margin: 10px auto;
justify-content: center;
display: block;
color: #fff;
background: #573b8a;
font-size: 1em;
font-weight: bold;
margin-top: 20px;
outline: none;
border: none;
border-radius: 5px;

7
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

transition: .2s ease-in;


cursor: pointer;
}
.b1:hover{
background: #6d44b8;
}
.h{
padding-top:20px;
}
</style>

<body>
<center>
<h1> Registration Page </h1>
<form name="f1" action="prg61.php" method="post">
<table>
<tr>
<td><lable> Enter Your First Name :- </lable></td>
<td><input type="text" placeholder="Enter Your First Name" name="t1" id="input"
required></td>
</tr>
<tr>
<td><lable> Enter Your Last Name :- </lable></td>
<td><input type="text" placeholder="Enter Your Last Name" name="t2" id="input"
required></td>
</tr>
<tr>
<td><lable> Enter Your Address :- </lable></td>
<td><textarea placeholder="Enter Your Address" rows="5" cols="35" name="t3"
id="input" required></textarea></td>
</tr>
<tr>
<td class="h"><lable> Enter Your Gender :- </lable></td>
<td class="h">
<input type="radio" name="Gender" value="Male">Male
<input type="radio" name="Gender" value="Female">Female
</td>
</tr>
<tr>
<td><lable> Enter Your Number :- </lable></td>
<td><input type="text" placeholder="Enter Your Number" name="t4" id="input"
required></td>
</tr>
<tr>

8
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

<td class="h"><lable> Hobbies :- </lable></td>


<td class="h">
<input type="checkbox" name="chkh1" value="Art">Arts
<input type="checkbox" name="chkh2" value="Sports">Sports
<input type="checkbox" name="chkh3" value="Travel">Travel
<input type="checkbox" name="chkh4" value="Computer">Computer
</td>
</tr>
<tr>
<td><input type="Reset" class="b1" name="re" onclick="CLEAR"
value="CLEAR"></td>
<td><input type="Submit" class="b1" name="su" onclick="REGISTER"
value="REGISTER"></td>
</tr>
</table>
</form>
</center>
</body>
</html>

Output 1 :

Redirect Data On Another Page.


<html>
<style>

9
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

body{
background-image: linear-gradient(to right top, #dc77b1, #d278bd, #c679c8, #b67cd3,
#a280dd, #8391ef, #5aa0fa, #00aeff, #00c7ff, #00dceb, #00ebb5, #48f46e);
}
</style>
<body>
<center>
<h1> You Have Enterd Details </h1>
<?php
echo "Your First Name Is :- ".$_POST['t1'];
echo "<br/><br/>";
echo "Your Last Name Is :- ".$_POST['t2'];
echo "<br/><br/>";
echo "Your Address Is :- ".$_POST['t3'];
echo "<br/><br/>";
echo "Your Gender Is :- ".$_REQUEST['Gender'];
echo "<br/><br/>";
echo "Your Number Is :- ".$_POST['t4'];
echo "<br/><br/>";
$b1 = "Not Selected";
$b2 = "Not Selected";
$b3 = "Not Selected";
$b4 = "Not Selected";

if(isset($_POST['chkh1']))
{
$b1="Selected";
}
if(isset($_POST['chkh2']))
{
$b2="Selected";
}
if(isset($_POST['chkh3']))
{
$b3="Selected";
}
if(isset($_POST['chkh4']))
{
$b4="Selected";
}
echo "Arts = $b1<br>Sports = $b2<br>Travel = $b3<br>Computer = $b4";
?>
</center>
</body>

10
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

</html>
Output 2 :

7. Write a PHP Program to Count Total No. of Visitors Using


Session.

Ans. Session Registration 1


<html>
<head>
<title> Session Form </title>
</head>
<body>
<form name="frm1" method="post" action="session2.php">
<h3> Enter Data </h3>
<table>
<tr>
<td> Enter Name : </td>
<td><input type="text" name="txtname" required placeholder="Name" ></td>
</tr>
<tr>
<td> Enter Number : </td>
<td><input type="tel" name="txtnum" required placeholder="Number" ></td>
</tr>
<tr>
<td> Enter Password : </td>

11
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

<td><input type="password" name="txtpas" required placeholder="Password"


></td>
</tr>
</table>
<input type="submit" value="Next">
</form>
</body>
</html>

Output 1 :

Session Registration 2

<html>
<head>
<title> Session Form 2 </title>
</head>
<body>
<form name="frm1" method="post" action="session3.php">
<h3> Enter Data </h3>
<table>
<tr>
<td> Enter Employee Id : </td>
<td><input type="text" name="txtemp" required placeholder="Employee Id" ></td>
</tr>
<tr>
<td> Enter Department Name : </td>
<td><input type="text" name="txtdep" required placeholder="Department Name"
></td>
</tr>
</table>
<input type="submit" value="Next">
</form>
<?php

12
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

session_start();
$na=$_POST['txtname'];
$nu=$_POST['txtnum'];
$pa=$_POST['txtpas'];
$_SESSION['na']=$na;
$_SESSION['nu']=$nu;
$_SESSION['pa']=$pa;
?>
</body>
</html>

Output 2 :

Session Data

<?php
session_start();
echo " Your Name : ".$_SESSION['na']."<br>";
echo " Your Number : ".$_SESSION['nu']."<br>";
echo " Your Password : ".$_SESSION['pa']."<br>";

$emp=$_POST['txtemp'];
$dep=$_POST['txtdep'];
$_SESSION['emp']=$emp;
$_SESSION['dep']=$dep;

echo " Your Employee Id : ".$_SESSION['emp']."<br>";


echo " Your Department Name : ".$_SESSION['dep']."<br>";

if(isset($_SESSION['VisitCnt']))
{
$_SESSION['VisitCnt'] += 1;
}

13
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

else
{
$_SESSION['VisitCnt'] =1;
}
$msg = "This page is Viewd ". $_SESSION['VisitCnt']." no of times in";
?>
<?php
echo ($msg);
?>

Output 3 :

8. Create a Simple PHP Form With Username (text field),


Password (password field), Remember (checkbox) & Login
(submit) button.
 If User Select ‘Remember’ Functionality, Save Username &
Password In Cookies.
 When Login Form Loads, Show Recently Saved Username &
Password From The Cookies.
 If User Do Not Select ‘Remember’, Cookies Will be Deleted.

Ans. User Log In Cookie.

<html>
<head>
<title> Cookies Program </title>
</head>
<style>
body
{

14
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

background-image: linear-gradient(to right bottom, #e73bf8, #ff32c3, #ff4e98, #ff717a,


#ff8f6e, #f6a367, #e9b669, #dac775, #c2d783, #a5e59c, #84f1bf, #5ffbe6);

}
</style>
<body>
<center>
<h1> User Log In Cookies </h1>
<form name="frm1" method="post" action="prg81.php">
<br>
<lable><b>User Name:-</b></lable>
<input type="text" Name="user"/></td>
<br>
<br>
<lable><b>Password:-</b></lable>
<input type="password" Name="password"/></td>
<br>
<br>
<input type="checkbox" value="Remember"><b>Remember
Me</b>
<input type="Submit" value="Login"/>
<br>
</form>
</center>
</body>
</html>

Output 1 :

Coockies
<html>
<head>

15
Name : Lathiya Vaibhav S. Sub : Web Framework And Services Roll. : 08

<title>User Log In Cookies</title>


</head>
<style>
body{
background-image: linear-gradient(to right top, #dc77b1, #d278bd, #c679c8, #b67cd3,
#a280dd, #8391ef, #5aa0fa, #00aeff, #00c7ff, #00dceb, #00ebb5, #48f46e);
}
</style>
<body>
<?php
$user=$_POST["user"];
$passowrd=$_POST["password"];
echo "User Name = ".$user."<br> Password =" .$passowrd;
echo "<br>";
echo "Welcome To PHP Program";
?>
</body>
</html>

Output 2 :

16

You might also like