WTCHANDANA
WTCHANDANA
WTCHANDANA
OBJECTIVE:
1(a): To Install XAMPP Stack Server.
RESOURCES:
XAMPP Stack Software.
PROCEDURE:
XAMPP INSTALLATION STEPS:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Step 9:
Now start the servers
RESOURCES:
Java Development Kit (JDK 1.6), Tomcat Apache Software
PROCEDURE:
Step 1:
Step 2:
Step 4:
Step 5:
Step 6:
Step 7:
STEP :8
Step 9:
OBJECTIVE:
RESOURCES:
Java Development Kit (JDK 1.6), Tomcat Software
PROCEDURE:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step7:
Step8:
Step9:
Step10:
Note: Setting up Java Development Kit
RESOURCES:
Java Development Kit (JDK 1.6), Tomcat Apache Software.
PROCEDURE:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
PROBLEM STATEMENT: . Implement the web application using PHP, The user is first served
a login page which takes user’s name and password. After submitting the details the server
checks these values against the data from a database and takes the following decisions. If name
and password matches, serves a welcome page with user’s full name. If name matches and
password doesn’t match, then serves “password mismatch” page If name is not found in the
database, serves a registration page, where user’s full name is asked and on submitting the full
name, it stores, the login name, password and full name in the database (hint: use session for
storing the submitted login name and password).
login.html
<DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<style> .myDiv {
border: 5px outset rgb(214, 56, 69);
background-image: #00FF99 text-
align: center; color :;white
}
</style>
<style> .center {
margin: auto; width: 60%;
border: 3px solid rgb(32, 173, 32);
padding: 20px;
}
</style>
</head>
<body>
<div class="center">
<div class="myDiv">
<form method="GET" action="logData.php">
<h1 style="color : white;">LOGIN PAGE</h1>
<label for="fname">User Name: </label>
<input type="text" id="fname" name="fname"><br><br>
<label for="password">Password: </label>
<input type="password" id="password" name="password"><br><br>
<button type="submit">Login</button>
</form>
</div>
</div>
</body>
</html>
REG.HTML
<DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
<style> .myDiv { border:
5px outset rgb(240, 48, 0); background-
image: url("image2.webp") ;
text-align: center;
color:white;
}
</style>
<style>
.center { margin:
auto; width:
60%;
border: 3px solid rgb(32, 173, 32);
padding: 20px;
}
</style>
<style> .myDiv1 {
border: 5px outset rgb(240, 48, 0);
background-color: #f7c761; text-
align: center;
}
</style>
<style>
.center1 {
margin: auto;
width: 60%;
border: 3px solid rgb(255, 179, 92);
padding: 20px;
}
</style>
</head>
<body>
<h1 style="color:rgb(0, 0, 0)"></h1>
<div class="center1">
<div class="myDiv1">
</div>
</div>
</body>
</html>
reg_data.php
<?php
$name = $_GET["uname"];
$p = $_GET["pwd"];
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"db_5e2") or die("No database");
$query = "select password from Login where Username = '".$name."'";
$r = mysqli_query($connection,$query) or die("no query");
$res = mysqli_fetch_array($r); if($res
== null){ header('Location:reg.html');
echo "Username Not Found";
} else{ if($p ==
$res['password']){
echo "Welcome $name";
}
else{ echo "
Password
mismatch";
}
}
mysqli_close($connection);
?>
Output:
Problem Statement : Implement the web application using PHP, A simple calculator web application
that takes two numbers and an operator (+, -, /, * and %)from an HTML page and returns the result
page with the operation performed on the operands, such that it stores each query in a database and
checks the database first for the result. If the query is already available in the Database, it returns the
value that was previously computed (from DB) or it computes the result and returns it after storing the
new query and result in Database.
Calculator.html :
<DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
<style>
.myDiv {
border: 5px outset rgb(240, 48, 0);
background-image: url("image2.webp") ;
text-align: center;
color:black;
}
</style>
<style>
.center {
margin: auto;
width: 60%;
border: 3px solid rgb(32, 173, 32);
padding: 20px;
}
</style>
</head>
<body>
<div class="center">
<div class="myDiv">
<h1> Calculator</h1>
<form method="Get" action="calData.php"><br><br>
<label for="num1">Number 1 : </label>
<input type="text" id="num1" name="num1"><br><br>
<label for="num2">Number 2 : </label>
<input type="text" id="num2" name="num2"><br><br>
<label for="opr">Operator : </label>
<select name="opr" id="opr">
<option value="+">add</option>
<option value="-">sub</option>
<option value="*">mul</option>
<option value="/">div</option>
<option value="%">mod</option>
</select><br><br>
<input type="Submit" value="Calculate"><br><br>
</form>
</div>
</div>
</body>
</html>
calData.php :
<?phpc
$n1=$_GET["num1"];
$n2=$_GET["num2"];
$op=$_GET["opr"];
$connection=mysqli_connect("localhost","root","")or die("could not connect to server");
$db=mysqli_select_db($connection,"db")or die("could not select database");
$ex=$n1.$op.$n2;
echo "Performing ".$n1.$op.$n2;
echo "<br>";
$query="select * from calc where exp='$ex'";
$result=mysqli_query($connection,$query)or die("Query failed".mysqli_error());
$num=mysqli_num_rows($result);
if($num!=0){
$value=mysqli_fetch_array($result);
echo "Printing from database";
echo "<br>";
echo "Result : ".$value["val"];
}
else{
echo "Printing from calculation";
echo "<br>";
$res=0;
switch($op){
case '+' : $res=$n1+$n2;
break;
case '-' : $res=$n1-$n2;
break;
case '*' : $res=$n1*$n2;
break;
case '/' : $res=$n1/$n2;
break;
case '%' : $res=$n1%$n2;
break;
}
echo "Result : ".$res;
}
?>
OUTPUT :
Problem Statement :
A. Implement the web application using PHP, A web application that lists all cookies stored in the
browser on clicking “List Cookies” button. Add cookies if necessary.
B. Implement the web application using PHP, which takes a name as input and on submit it shows
a hello page where is takenfrom the request. It shows the start time at the right top corner of
thepage and provides a logout button. On clicking this button, it shouldshow a logout page
with Thank You message with the durationof usage (hint: Use session to store name and time).
Program:
Cookies(A) :
Cookie.html:
<html>
<head>
<title> Choose List Cookies </title>
<style>
.myDiv {
border: 5px outset rgb(214, 56, 69);
background-image: url("image2.webp") ;
text-align: center;
color :black;
}
</style>
<style>
.center {
margin: auto;
width: 60%;
border: 3px solid rgb(32, 173, 32);
padding: 20px;
}
</style>
</head>
<body><div class="center">
<div class="myDiv">
<br><br>
<form action="Displaycookie.php" method="POST"/>
<label for="fname">Name</label>
<input type="text" id=fname name=fname><br><br>
<label for="age">Age</label>
<input type="text" id=age name=age><br><br>
<input type="submit" name="submit" value="List Cookies"/>
</form>
</div>
</div>
</body>
</html>
displaycookie.php:
<?php
if(isset($_POST["fname"]) && isset($_POST["age"])){
$key=$_POST["fname"];
$value=$_POST["age"];
setcookie($key,$value);}
$cookie=$_COOKIE;
foreach ($cookie as $key=>$val)
echo "<br>$key : $val";
?>
OUTPUT :
Sessions:
home.html :
<html>
<head>
<title>Index</title>
<link ref="stylesheet" href="login.css">
</head>
<body>
<div class="myDiv>
<div class="center">
<form name="form1" method="post">
<table align="center" width="70%" border="0" cellpadding="3" cellspacing="1">
<br/>
<tr>
<td>Name : </td>
<td><input name="uname" type="text"></td>
</tr>
<tr>
<td></td>
<td ><input type="submit" name="Submit" value="SUBMIT"></td>
</tr>
</table>
</form>
</div>
</div>
<?php
if(isset($_POST['Submit']))
{
date_default_timezone_set('Asia/Kolkata');
$currentTime = date( 'h:i:s A', time () );
$uname=$_POST["uname"];
session_start();
$_SESSION["name"] = $_POST["uname"];
$_SESSION["stime"] = $currentTime;
header('Location: Home.php');
}
?>
</body>
</html>
Home.php
<html>
<head>
<title>Welcome </title>
</head>
<body>
<br/>
<?php
session_start();
$stime=$_SESSION['stime'];
echo "<p align='right'><b>".$_SESSION['stime']."</b></p>";
echo "Welcome : ".$_SESSION['name'];
?>
<form name="form1" method="post">
<input type="submit" name="logout" value="LOGOUT">
</form>
<?php
if(isset($_POST['logout']))
{
$uname=$_POST["uname"];
date_default_timezone_set('Asia/Kolkata');
$currentTime = date( 'h:i:s A', time () );
session_start();
$_SESSION["stime"] = $_SESSION['stime'];
$_SESSION["etime"] = $currentTime;
header('Location: Welcome.php');
}
?>
</body>
</html>
Welcome.php
<html>
<head>
<title>Welcome</title>
</head>
<body>
<?php
session_start();
echo "Thank You ".$_SESSION["name"]."<br/>";
$stime=$_SESSION['stime'];
$etime=$_SESSION['etime'];
echo "Login time is :". $stime."<br/>";
echo "Logout time is : ".$etime."<br/>";
$time1 = new DateTime($stime);
$time2 = new DateTime($etime);
$interval = $time1->diff($time2);
echo "Duration is :" . $interval->format('%s second(s)');
?>
</body>
</html>
OUTPUT:
Problem Statement :Write a php program to display a welcome page.
Code:
<h1>
<?php
Echo"Welcome Chandana"
?>
</h1>
Output :
Problem Statement :Write a php program to display the factorial of a given number.
Code:
Factorial.html:
<!DOCTYPE html>
<head>
<title>Factorial Calculator</title>
<style>
.myDiv {
border: 5px outset rgb(214, 56, 69);
background-color: rgb(165, 105, 189);
text-align: center;
color :white;
}
</style>
<style>
.center {
margin: auto;
width: 60%;
border: 3px solid rgb(32, 173, 32);
padding: 20px;
}
</style>
</head>
<body>
<div class="center">
<div class="myDiv">
<h2>Factorial Calculator</h2>
<form action="fact.php" method="post">
<label for="number">Enter an Integer:</label><br>
<input type="number" id="number" name="number" required><br><br>
<input type="submit" value="fact">
</form>
</div>
</div>
</body>
</html>
Fact.php:
<?php
if (isset($_POST["number"]) && !empty($_POST["number"])) {
$number = intval($_POST["number"]);
if ($number >= 0) {
// Calculate factorial
$factorial = 1;
for ($i = 2; $i <= $number; $i++) {
$factorial *= $i;
}
echo "Factorial of " . $number . " is " . $factorial . ".";
} else {
echo "Please enter a valid positive integer.";
}
}
?>
Output:
Problem Statement: :Write a php program to sort the array of Strings using the Built-in functions.
Code:
sortString.php:
<?php
$strings = array("This", "is", "Web", "Technologies", "Lab");
sort($strings);
echo "Sorted array in ascending order:<br>";
print_r($strings);
echo"<br>";
rsort($strings);
echo "\nSorted array in descending order:<br>";
print_r($strings);
echo"<br>";
?>
Output:
Problem Statement : write a php program to display whether a number is even or odd.
Code:
EvenOdd.html:
<!DOCTYPE html>
<head>
<title>Even/Odd Checker</title>
<style>
.myDiv {
border: 5px outset rgb(214, 56, 69);
background-color: rgb(165, 105, 189);
text-align: center;
color :white;
}
</style>
<style>
.center {
margin: auto;
width: 60%;
border: 3px solid rgb(32, 173, 32);
padding: 20px;
}
</style>
</head>
<body>
<div class="center">
<div class="myDiv">
<h2>Even/Odd Checker</h2>
<form action="process.php" method="post">
<label for="number">Enter an Integer:</label><br>
<input type="number" id="number" name="number" required><br><br>
<input type="submit" value="Check">
</form>
</div>
</div>
</body>
</html>
Process.php:
<?php
if (isset($_POST["number"]) && !empty($_POST["number"])) {
$number = intval($_POST["number"]);
if ($number % 2 == 0) {
echo "The number " . $number . " is even.";
} else {
echo "The number " . $number . " is odd.";
}
} else {
echo "Please enter a valid integer.";
}
?>
Output:
Problem Statement : write a php program to perform the following String Operations:
• String Length.
• String Concatenation..
• Replace a substring with another substring.
Code:
StringOps.php:
<?php
$string = "We are currently working to learn web technologies";
// 2. Concatenation
$newString = $string . " by Lalitha mam.";
echo "Concatenated string: $newString<br>";
if ($input1) {
// Read from input file using fread
$content = fread($input1, filesize($inputFile));
fclose($input1);
$output1 = fopen($outputFile, "w");
if ($output1) {
fwrite($output1, $content);