20BCE2904 - Lab Assignment 3
20BCE2904 - Lab Assignment 3
20BCE2904 - Lab Assignment 3
Engineering
CSE3002-Internet and Web Programming
Fall 2022-23
Slot: - L19 + L20
Lab Assignment 3
PHP
Submitted By:
BIJAN SHRESTHA
B.Tech Computer Science and Engineering
Reg No. : 20BCE2904
SUBMITTED TO:
PROF. Dr. Rajkumar R
Asst. Prof. Grade 2
School of Computer Science and Engineering
VIT University
Vellore-14, INDIA
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Name</title>
</head>
<body>
<form method='POST'>
<h2>Please input your name:</h2>
<input type="text" name="name">
<input type="submit" value="Submit Name">
</form>
<?php
$name = $_POST['name'];
echo "<h3> Hello $name </h3>";
?>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Palindrome</title>
</head>
<body>
<form method="post">
Enter a Number: <input type="text" name="num" /><br>
<button type="submit">Check</button>
</form>
<?php
if ($_POST) {
$num = $_POST['num'];
$reverse = strrev($num);
if ($num == $reverse) {
echo "The number $num is Palindrome";
} else {
echo "The number $num is not a Palindrome";
}
}
?>
</body>
</html>
Output:
</html>
Output:
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Largest number</title>
</head>
<body>
<form method="post" action="submit.php">
Enter the first number:<br>
<input type="text" name="num1"><br>
Enter the second number:<br>
<input type="text" name="num2"><br>
Enter the third number:<br>
<input type="text" name="num3">
<br>
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
Bijan Shrestha CSE3002-IWP Lab Reg no. 20BCE2904
if (isset($_POST["submit"])) {
$num1 = $_POST["num1"];
$num2 = $_POST["num2"];
$num3 = $_POST["num3"];
if ($num1 > $num2 && $num1 > $num3) {
echo "Largest number among $num1, $num2 and $num3 is:
$num1\n";
} else {
if ($num2 > $num1 && $num2 > $num3) {
echo "Largest number among $num1, $num2 and $num3 is:
$num2\n";
} else
echo "Largest number among $num1, $num2 and $num3 is:
$num3\n";
}
}
Output:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
background:
url('https://i.pinimg.com/originals/8c/43/64/8c43645fe8d0ac164a6925448be32858.jpg ');
height: 100%;
}
.container {
text-align: center;
margin-top: 23px;
}
table {
margin: auto;
}
input {
border-radius: 21px;
border: 5px solid #838383;
background-color: bisque;
font-size: 34px;
height: 90px;
width: 456px;
}
button {
border-radius: 30%;
font-size: 40px;
background: #ffffff;
width: 102px;
height: 80px;
margin: 6px;
}
h1 {
font-size: 30px;
font-family: 'Times New Roman',
Times,
serif;
}
.color {
background-color: beige;
}
</style>
</head>
<body>
<div class="container">
<h1>Calculator</h1>
<div class="calculator">
<input type="text" name="screen" id="screen">
<table>
<tr>
<td><button class="color">(</button></td>
<td><button class="color">)</button></td>
<td><button class="color">%</button></td>
<td><button class="color">AC</button></td>
</tr>
<tr>
<td><button>7</button></td>
<td><button>8</button></td>
<td><button>9</button></td>
<td><button class="color">X</button></td>
</tr>
<tr>
<script type="text/javascript">
let screen = document.getElementById('screen');
buttons = document.querySelectorAll('button');
let screenValue = '';
for (item of buttons) {
item.addEventListener('click', (e) => {
buttonText = e.target.innerText;
console.log('Button text is ', buttonText);
if (buttonText == 'X') {
buttonText = '*';
screenValue += buttonText;
screen.value = screenValue;
} else if (buttonText == 'AC') {
screenValue = "";
screen.value = screenValue;
} else if (buttonText == '=') {
screen.value = eval(screenValue);
} else {
screenValue += buttonText;
screen.value = screenValue;
}
})
}
</script>
</body>
</html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Age Calculator</title>
<style>
body {
background-image:
url('https://png.pngtree.com/thumb_back/fh260/background/20200703/pngtree-
mathematics-education-calculator-ruler-hand-drawn-background-image_340649.jpg');
background-repeat: no-repeat;
background-size: 100%;
}
h1 {
font-size: 300%;
color: chocolate;
}
b {
font-size: 150%;
color: chocolate;
}
button {
width: 120px;
background-color: bisque;
color: chocolate;
border: 2px saddlebrown solid;
}
</style>
<script type="text/javascript">
function ageCalculator() {
var inp = document.getElementById("DOB").value;
var dob = new Date(inp);
var mnth = Date.now() - dob.getTime();
var ag = new Date(mnth);
var yr = ag.getUTCFullYear();
var age = Math.abs(yr - 1970);
return document.getElementById("result").innerHTML = "Age is: " + age +
<body>
<center>
<h1>Age Calculator</h1>
<b> Enter Date of Birth: <input type=date id=DOB> </b> <br><br>
<button type="submit" onclick="ageCalculator()"> Calculate Age
</button> <br><br>
<h3 style="color: chocolate; font-size: 150%;" id="result"
align="center"></h3>
</center>
</body>
</html>
Output:
Output:
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Function</title>
</head>
<body>
<?php
//add() function with two parameter
function add($x, $y)
{
$sum = $x + $y;
echo "Sum = $sum <br><br>";
}
//sub() function with two parameter
function sub($x, $y)
{
$sub = $x - $y;
echo "Diff = $sub <br><br>";
}
//call function, get two argument through input box and click on add or sub button
if (isset($_POST['add'])) {
//call add() function
add($_POST['first'], $_POST['second']);
}
if (isset($_POST['sub'])) {
//call add() function
sub($_POST['first'], $_POST['second']);
}
?>
<form method="post">
Enter first number: <input type="number" name="first" /><br><br>
Enter second number: <input type="number" name="second" /><br><br>
<input type="submit" name="add" value="ADDITION" />
<input type="submit" name="sub" value="SUBTRACTION" />
</form>
</body>
</html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="login.php" method="post">
<table border="2" align="center" height="40%" width="30%"><br>
<tr align="center">
<td colspan="2">
<h2>LOGIN PAGE</h2>
</td>
</tr>
<tr align="center">
<td><input type="text" size="9" value=" User Name" readonly></td>
<td><input type="text" name="u"></td>
</tr>
<tr align="center">
<td><input type="text" size="9" value=" Password" readonly></td>
<td><input type="password" name="p"></td>
</tr>
</table>
<table align="center" height="20%" width="40%">
<tr align="center">
<td><input type="submit" value="SUBMIT"></td>
<td><input type="reset" value="CLEAR"></td>
</tr>
</table>
</body>
</html>
<?php if ($_POST) {
$un = $_POST['u'];
$pw = $_POST['p'];
if ($un == "bijan" && $pw == "1234") {
Output:
Successful login-
invalid Details:
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Array</title>
</head>
<body>
<?php
$i = Array_sum($b);
print_r($i);
</body>
</html>
Output:
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Personal details</title>
</head>
</html>
Output:
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cookies Counter</title>
</head>
<body>
<?php
$total_count = 0;
if (isset($_COOKIE['count'])) {
$total_count = $_COOKIE['count'];
$total_count++;
}
if (isset($_COOKIE['last_visit'])) {
$last_visit = $_COOKIE['last_visit'];
}
setcookie('count', $total_count);
setcookie('last_visit', date("H:i:s"));
if ($total_count == 0) {
echo "Welcome! We are glad to see you here.";
} else {
echo "This is your visit number " . $total_count;
echo '<br>';
echo "Last time, you were here at " . $last_visit;
}
?>
</body>
</html>
Output:
Code:
Output:
Code:
Output:
Code:
Output:
Code:
Code:
Output: