WT 2 Practical book Assingment
Assignment1
Set A
1. Write a PHP script to keep track of number of times the web page has been
access. [Use session and cookies]
<html>
<head><title>counter</title></head>
<form method=”GET” action=”counter.php”>
<input type=”submit” value=”submit”></input>
</form>
</html>
Counter.php
<?php
Session_start();
If(isset($_SESSION[‘cnt’]))
{
$_SESSION[‘cnt’]+=1;
echo”you have visited this page “.$_SESSION[.cnt].”times”;
}
else
{
$_SESSION[‘cnt’]=1;
echo”you have visited this page “.$_SESSION[.cnt].”times”;
}
}
?>
<html>
<body>
<a href=”counter.php”>Refresh</a>
</body></html>
2. Write a PHP script to change the preferences of your web page like font
style, font size, font color, background color using cookie. Display selected
setting on next web page and actual implementation (with new settings) on
third page.
1.html-
<html>
<body>
<form action="2.php" method="get">
<center>
<b>Select font style :</b><input type=text name=s1>
<b>Enter font size : </b><input type=text name=s>
<b>Enter font color :</b><input type=text name=c>
<b>Enter background color :</b><input type=text name=b>
<input type=submit value="Next">
</center>
</form>
</body>
</html>
2.php-
<?php
echo "style is ".$_GET['s1']."
color is ".$_GET['c']."
Background color is ".$_GET['b']."
size is ".$_GET['s'];
setcookie("set1",$_GET['s1'],time()+3600);
setcookie("set2",$_GET['c'],time()+3600);
setcookie("set3",$_GET['b'],time()+3600);
setcookie("set4",$_GET['s'],time()+3600);
?>
<a href="3.php">Show</a>
3.php-
<?php
$style=$_COOKIE['set1'];
$color=$_COOKIE['set2'];
$size=$_COOKIE['set4'];
$b_color=$_COOKIE['set3'];
$msg="Genus iT Solution";
echo "<body bgcolor=$b_color>";
echo "<font color=$color size=$size face=$style>$msg";
echo "</font></body>";
?>
Display selected settings on next web page and actual
implementation (with new settings) on third web
page.
csprogramx November 02, 2020
Change the preferences of your web page like font style, font size,
font color, background color using cookie. Display selected settings on
next web page and actual implementation (with new settings) on third
web page.
ex6setb2b.html
<html>
<head><title>SETB2 PROGRAM</title></head>
<body>
<form action="ex6setb2b.php" method="post">
FONT STYLE<input type="text"name="fstyle"><br>
FONT SIZE<input type="text"name="fsize" ><br>
FONT COLOUR<input type="text"name="fcolour"><br>
BACKGROUND COLOUR<input type="text"name="bcolour"><br>
<input type="submit"name="submit" value="submit">
</form>
</body>
</html>
ex6setb2b.php
<?php
$fstyle=$_POST['fstyle'];
$fsize=$_POST['fsize'];
$fcolour=$_POST['fcolour'];
$bcolour=$_POST['bcolour'];
setcookie("fstyle","$fstyle",time()+3660);
setcookie("fsize","$fsize",time()+3600);
setcookie("fcolour","$fcolour",time()+3600);
setcookie("bcolour","$bcolour",time()+3600);
echo "<h1> YOUR PREFERENCES </h1><br>";
echo "FONT STYLE:<b>$fstyle</b><br>";
echo "FONT SIZE:<b>$fsize px</b><br>";
echo "FONT COLOUR:<b>$fcolour</b><br>";
echo "BACKGROUND COLOUR:<b>$bcolour</b><br>";
?>
<html>
<form action="ex6setb2c.php" method="post">
<input type="submit" value="click to apply preferences">
</form>
</html>
ex6setb2c.php
<?php
$fstyle=$_COOKIE['fstyle'];
$fsize=$_COOKIE['fsize'];
$fcolour=$_COOKIE['fcolour'];
$bcolour=$_COOKIE['bcolour'];
?>
<html>
<body bgcolor="<?php echo $bcolour?>">
<font size="<?php echo $fsize?>" color="<?php echo $fcolour?>" face="<?php echo $fstyle?
>"> ALL PROPERTIES ARE APPLIED</font>
</body>
</html>
Set B
1. Write a PHP script to accept username and password. If in the first three
chances, username and password entered is correct then display second form
with “Welcome message” otherwise display error message. [Use Session]
HTML file :
<html>
<head>
<script>
function getans()
{
st1=document.getElementById('txtname').value;
st2=document.getElementById('txtpass').value;
ob=new XMLHttpRequest();
ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
{
if(ob.responseText==3)
{
alert("sorry you lost the chances to login");
location="error.html";
}
else if(ob.responseText=="correct")
{
alert("you entered correct details");
}
else alert(ob.responseText);
}
}
ob.open("GET","slip8_Q2.php?n="+st1+"&p="+st2);
ob.send();
}
</script>
</head>
<body>
<input type=text id=txtname placeholder="username"></br>
<input type=password id=txtpass placeholder="password"></br>
<input type="button" onclick="getans()" value="Login">
</body>
</html>
HTML file : error.html
<html>
<body>
<h1>YOu lossed the chances of login</h1>
</body>
</html>
PHP file :
<?php
session_start();
$nm=$_GET['n'];
$ps=$_GET['p'];
if($nm==$ps)
{
echo "correct";
}
else if(isset($_SESSION['cnt']))
{
$x=$_SESSION['cnt'];
$x=$x+1;
$_SESSION['cnt']=$x;
echo $_SESSION['cnt'];
if($_SESSION['cnt']>=3)
$_SESSION['cnt']=1;
}
else
{
$_SESSION['cnt']=1;
echo "1";
}
?>
2. Write a PHP script to accept Employee details (Eno, Ename, Address) on
first page. On second page accept earning (Basic, DA, HRA). On third page
print Employee information (Eno, Ename, Address, Basic, DA, HRA, Total)
[ Use Session]
Emp.html
<html>
<body>
<form method="POST" action="Lic.php">
Enter EMP No : <input type=text name="eno"><br>
Enter EMP Name : <input type=text name="name"><br>
Enter Address : <input type=text name="addr"><br>
<input type=submit value=Submit>
</form>
</body>
</html>
LIC.php
<?php
session_start();
$_SESSION['eno']=$_POST['eno'];
$_SESSION['name']=$_POST['name'];
$_SESSION['addr']=$_POST['addr'];
echo"Hello ".$_SESSION['name']." enter LIC details<br>";
?>
<form method="POST" action="Display.php">
Plan No:<input type="text" name="pno"><br>
Plan Name :<input type="text" name="pname"><br>
Premium :<input type="text" name="pre"><br>
<input type=submit value=Display>
</form>
Display.php
<?php
session_start();
echo"<Center>"."<b>Employee Details</b>"."<br>";
echo"Emp No:".$_SESSION['eno']."<br>";
echo"Emp name:".$_SESSION['name']."<br>";
echo"Address:".$_SESSION['addr']."<br>"."<hr>";
echo"<b>LIC Plan Details:</b>"."<br>";
echo"Plan No:".$_REQUEST['pno']."<br>";
echo"Plan Name:".$_REQUEST['pname']."<br>";
echo"Premium:".$_REQUEST['pre']."<br>"."<hr>";
?>
Email ThisBlogThis!Share to TwitterShare to Facebook
Set C
1. Crete a form to accept customer information ( Name, Addr, MobNo). Once the
customer information is accepted, accept product information in the next form
(ProdName, Qty,Rate). Generate the bill for the customer in the next form. Bill
should contain the customer information and the information of the products
entered.
https://bcapractical2017.blogspot.com/2021/05/phps23.html