0% found this document useful (0 votes)
8 views14 pages

Internet and WebTechnology Lab

The document provides code examples for various web applications using PHP, HTML, CSS, and JavaScript. It includes examples for cookies, sessions, file uploads, employee salary retrieval, a simple calculator, a contact form, and a user information form. Each section contains the HTML structure and corresponding PHP scripts for functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Internet and WebTechnology Lab

The document provides code examples for various web applications using PHP, HTML, CSS, and JavaScript. It includes examples for cookies, sessions, file uploads, employee salary retrieval, a simple calculator, a contact form, and a user information form. Each section contains the HTML structure and corresponding PHP scripts for functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Page-1

1. Design a web page to show the use of cookies in php.


Code:
<?php
// Set cookie
setcookie("username", "Vidyasagar University", time() + 3600); // 1 hour
?>
<!DOCTYPE html>
<html>
<head>
<title>Cookie Example</title>
</head>
<body>
<h2>PHP Cookie Example</h2>
<?php
if (isset($_COOKIE["username"])) {
echo "Welcome, " . $_COOKIE["username"];
} else {
echo "Cookie is set. Refresh the page to see the value.";
}
?>
</body>
</html>
OUTPUT:
Page-2

2. Design a web page to show the use of session in php.


Code:
<?php
session_start(); // start the session
// set session variable
$_SESSION["username"] = "MCA";
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Session Example</title>
</head>
<body>
<h2>PHP Session Example</h2>
<?php
if (isset($_SESSION["username"])) {
echo "Welcome, " . $_SESSION["username"];
} else {
echo "Session is not set";
}
?>
</body>
</html>

OUTPUT:
Page-3

3. Design a web page to upload a file with basic details of an


uploader.
Code:
<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<h2>File Upload Form</h2>
<form action="[Link]" method="post" enctype="multipart/form-data">
Name:
<input type="text" name="name" required><br><br>
Email:
<input type="email" name="email" required><br><br>
Select File:
<input type="file" name="myfile" required><br><br>
<input type="submit" value="Upload File">
</form>
</body>
</html>

PHP File:
<?php
$name = $_POST["name"];
$email = $_POST["email"];

$file_name = $_FILES["myfile"]["name"];
$temp_name = $_FILES["myfile"]["tmp_name"];
Page-4

// Create uploads folder manually before running


move_uploaded_file($temp_name, "uploads/" . $file_name);

echo "<h3>File Uploaded Successfully</h3>";


echo "Name: " . $name . "<br>";
echo "Email: " . $email . "<br>";
echo "File Name: " . $file_name;
?>

OUTPUT:
Before submitting:

After submitting:
Page-5

4. Create a web page to access and display the salary of an


employee from a database table.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Employee Salary</title>
</head>
<body>

<h2>Check Employee Salary</h2>

<form action="[Link]" method="post">


Employee ID:
<input type="number" name="emp_id" required>
<br><br>
<input type="submit" value="Get Salary">
</form>

</body>
</html>

PHP File:
<?php
$conn = mysqli_connect("localhost", "root", "", "company");

if (!$conn) {
die("Database connection failed");
}

$emp_id = $_POST["emp_id"];

$sql = "SELECT emp_name, salary FROM employee WHERE emp_id='$emp_id'";


Page-6

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
echo "Employee Name: " . $row["emp_name"] . "<br>";
echo "Salary: ₹" . $row["salary"];
} else {
echo "Employee not found";
}

mysqli_close($conn);
?>

OUTPUT:
Page-7

5. Design a simple calculator using html css and js.


Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple Calculator</title>

<style>
body {
text-align: center;
font-family: Arial;
}
.calculator {
width: 220px;
margin: auto;
border: 2px solid black;
padding: 10px;
}
input {
width: 200px;
height: 30px;
text-align: right;
margin-bottom: 10px;
font-size: 18px;
}
button {
width: 45px;
height: 35px;
margin: 2px;
font-size: 16px;
}
Page-8

</style>
</head>

<body>

<h2>Simple Calculator</h2>
<div class="calculator">
<input type="text" id="result" readonly><br>
<button onclick="show('1')">1</button>
<button onclick="show('2')">2</button>
<button onclick="show('3')">3</button>
<button onclick="show('+')">+</button><br>
<button onclick="show('4')">4</button>
<button onclick="show('5')">5</button>
<button onclick="show('6')">6</button>
<button onclick="show('-')">−</button><br>
<button onclick="show('7')">7</button>
<button onclick="show('8')">8</button>
<button onclick="show('9')">9</button>
<button onclick="show('×')">&times;</button><br>
<button onclick="show('0')">0</button>
<button onclick="clearBox()">C</button>
<button onclick="calculate()">=</button>
<button onclick="show('÷')">&divide;</button>
</div>
<script>
function show(val) {
[Link]("result").value += val;
}
function clearBox() {
[Link]("result").value = "";
}
Page-9

function calculate() {
let exp = [Link]("result").value;
exp = [Link](/×/g, '*');
exp = [Link](/÷/g, '/');
[Link]("result").value = eval(exp);
}
</script>

</body>
</html>

OUTPUT:
Page-10

[Link] a contact us webpage and to collect email and message


with contact information and send it to another web page.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Contact Us</title>
</head>
<body>

<h2>Contact Us</h2>

<p>
Phone: 9876543768 <br>
Email: icc@[Link] <br>
Address: Kolkata,India
</p>

<form action="[Link]" method="post">


Your Email:
<input type="email" name="email" required>
<br><br>

Your Message:
<textarea name="message" rows="4" cols="30" required></textarea>
<br><br>

<input type="submit" value="Send">


</form>

</body>
</html>
Page-11

PHP File:
<!DOCTYPE html>
<html>
<head>
<title>Contact Details</title>
</head>
<body>
<h2>Message Received</h2>
<?php
$email = $_POST["email"];
$message = $_POST["message"];
echo "Email: " . $email . "<br><br>";
echo "Message: " . $message;
?>
</body>
</html>

OUTPUT:
Page-12

7. Design a form with atleast three fields and send the information
with another webpage.
Code:
<!DOCTYPE html>
<html>
<head>
<title>User Form</title>
</head>
<body>
<h2>User Information Form</h2>
<form action="[Link]" method="post">
Name:
<input type="text" name="name" required>
<br><br>
Email:
<input type="email" name="email" required>
<br><br>
Age:
<input type="number" name="age" required>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

PHP File:
<!DOCTYPE html>
<html>
<head>
<title>Form Output</title>
</head>
<body>
<h2>Submitted Information</h2>
Page-13

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$age = $_POST["age"];
echo "Name: " . $name . "<br>";
echo "Email: " . $email . "<br>";
echo "Age: " . $age;
?>
</body>
</html>

OUTPUT:

After submit:
INDEX

PAGE
[Link] DESCRRIPTION
NO
Design a web page to show the use of cookies in
1 1
php.

2 Design a web page to show the use of session in 2


php.
Design a web page to upload a file with basic
3 3-4
details of an uploader.
Create a web page to access and display the salary
4 5-6
of an employee from a database table.

5 Design a simple calculator using html css and js. 7-9


Create a contact us webpage and to collect email
6 and message with contact information and send it 10-11
to another web page.
Design a form with atleast three fields and send
7 12-13
the information with another webpage.

Signature :

Date :

You might also like