Assignment 1: Set A
Assignment 1: Set A
-------------------------------------------------------------------------------------------------------------------------------
Set A
Q1)PHP script to keep track of number of times the web page has been access
Ans :
<?php
session_start();
if(isset($_SESSION['count']))
$_SESSION['count']=$_SESSION['count']+1;
else
$_SESSION['count']=1;
?>
Q2)Write a PHP script to change the preference of your web page like font style, font, size, font color,
background color using cookie. Display selected settings on next page and actual implementation ( with
new settings) on third page.
Ans :
HTML file :
<html>
<body>
</form>
</body>
</html>
setcookie("set1",$_GET['s1'],time()+3600);
setcookie("set2",$_GET['c'],time()+3600);
setcookie("set3",$_GET['b'],time()+3600);
setcookie("set4",$_GET['s'],time()+3600);
?>
<html>
<body>
<form action="display.php">
</form>
</body>
</html>
$color = $_COOKIE['set2'];
$size = $_COOKIE['set4'];
$b_color = $_COOKIE['set3'];
$msg = "Vrushali";
echo "</font></body>";
?>
------------------------------------------------------------------------------------------------------------------------------------
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]
Ans :
Html file
<html>
<head>
</head>
<body>
</html
Php File
<?php
session_start();
$nm=$_POST["unm"];
$ps=$_POST["pass"];
{
}
else
{
if($_SESSION['cnt']==3)
{
$SESSION['cnt'] = 0;
}
else if($cnt<3)
{
echo " you have chanced".$_SESSION['cnt'];
$_SESSION['cnt'] = $_SESSION['cnt'] + 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]
Ans :
Html File
<html>
<body>
<b>
</form>
</body>
</html>
Earning File
<?php
session_start();
$_SESSION["eno"]=$_POST["t1"];
$_SESSION["enm"]=$_POST["t2"];
$_SESSION["add"]=$_POST["t3"];
echo "<bR> Hello ".$_SESSION["enm"]." Plz Fill your Earning Details ";
?>
Display File
<?php
$a = $_POST["t4"];
$b = $_POST["t5"];
$c = $_POST["t6"];
session_start();
$sum = $a + $b + $c;
?>
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.
Ans :
HTML File
<html>
<body>
</form>
</body>
</html>
Product.php
<?php
session_start();
$_SESSION["cnm"]=$_POST["t1"];
$_SESSION["add"]=$_POST["t2"];
$_SESSION["mob"]=$_POST["t3"];
echo "<bR> Hello ".$_SESSION["cnm"]." Plz Enter Your Product Details ";
?>
Display3.php
<?php
$a = $_POST["t4"];
$b = $_POST["t5"];
$c = $_POST["t6"];
session_start();
$total = $b*$c;
?>