Web Technology Lab
Web Technology Lab
Here’s a basic TCP server-client example in Python using the socket module.
Server (server.py)
python
CopyEdit
import socket
host = '127.0.0.1'
port = 12345
server_socket.bind((host, port))
# Listen for incoming connections
server_socket.listen(1)
while True:
data = client_socket.recv(1024).decode()
print(f"Received: {data}")
client_socket.send(response.encode())
client_socket.close()
Client (client.py)
python
CopyEdit
import socket
# Create a socket object
host = '127.0.0.1'
port = 12345
client_socket.connect((host, port))
client_socket.send(message.encode())
response = client_socket.recv(1024).decode()
client_socket.close()
nginx
CopyEdit
python server.py
nginx
CopyEdit
python client.py
2. Backend (optional) – Uses technologies like Node.js, Django, or PHP for processing.
Let's create a basic web application that takes user input and displays it dynamically.
1. HTML (index.html)
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<button onclick="displayText()">Submit</button>
<p id="output"></p>
</div>
<script src="script.js"></script>
</body>
</html>
2. JavaScript (script.js)
javascript
CopyEdit
function displayText() {
3. CSS (styles.css)
css
CopyEdit
body {
text-align: center;
margin: 50px;
.container {
background: #f4f4f4;
padding: 20px;
border-radius: 10px;
width: 300px;
margin: auto;
button {
margin-top: 10px;
background: blue;
color: white;
border: none;
cursor: pointer;
}
3)Developing Advanced Web Application Programs using CSS
1. HTML (index.html)
html
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<header>
</header>
<div class="container">
<div class="card">
<h2>Feature 1</h2>
</div>
<div class="card">
<h2>Feature 2</h2>
<p>Responsive layout using Flexbox.</p>
</div>
<div class="card">
<h2>Feature 3</h2>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
2. CSS (styles.css)
css
CopyEdit
/* Global Styles */
body {
text-align: center;
margin: 0;
padding: 0;
/* Header */
header {
padding: 20px;
font-size: 24px;
font-weight: bold;
.container {
display: flex;
justify-content: center;
gap: 20px;
flex-wrap: wrap;
padding: 20px;
.card {
background: white;
padding: 20px;
border-radius: 10px;
width: 250px;
/* Hover Effect */
.card:hover {
transform: scale(1.05);
/* Animated Button */
.animated-button {
background: #ff4b2b;
color: white;
border: none;
font-size: 16px;
margin-top: 20px;
border-radius: 5px;
cursor: pointer;
.animated-button:hover {
background: #ff7e5f;
transform: translateY(-3px);
/* Responsive Design */
.container {
flex-direction: column;
3. JavaScript (script.js)
javascript
CopyEdit
document.querySelector('.animated-button').addEventListener('click', function() {
});
php
CopyEdit
<?php
Run this file on a local server by placing it inside the htdocs (for XAMPP) or www (for WAMP)
folder.
PHP variables start with $ and do not require explicit type declarations.
php
CopyEdit
<?php
?>
4. Conditional Statements
php
CopyEdit
<?php
$age = 18;
?>
5. Loops
For Loop
php
CopyEdit
<?php
?>
While Loop
php
CopyEdit
<?php
$x = 1;
$x++;
?>
6. Functions
php
CopyEdit
<?php
function greet($name) {
echo greet("Alice");
?>
7. Handling Forms
html
CopyEdit
<button type="submit">Submit</button>
</form>
php
CopyEdit
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['username'];
?>
sql
CopyEdit
USE myapp;
);
php
CopyEdit
<?php
$host = "localhost";
$db = "myapp";
if ($conn->connect_error) {
?>
php
CopyEdit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User Registration</title>
</head>
<body>
<h2>Register</h2>
</form>
</body>
</html>
php
CopyEdit
<?php
include 'config.php';
if (isset($_POST['register'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$sql = "INSERT INTO users (name, email, password) VALUES ('$name', '$email',
'$password')";
if ($conn->query($sql) === TRUE) {
} else {
$conn->close();
?>
css
CopyEdit
body {
text-align: center;
margin: 50px;
input, button {
margin: 5px;
padding: 10px;
width: 200px;
}
button {
background-color: blue;
color: white;
border: none;
sql
CopyEdit
USE school;
name VARCHAR(100),
email VARCHAR(100),
course VARCHAR(100)
);
Folder Structure
pgsql
CopyEdit
/student-app
┣ config/
┣ business/
┣ public/
php
CopyEdit
<?php
function getStudents() {
global $conn;
return $conn->query($sql);
global $conn;
$stmt = $conn->prepare("INSERT INTO students (name, email, course) VALUES (?, ?, ?)");
?>
php
CopyEdit
<!DOCTYPE html>
<html>
<head><title>Student Manager</title></head>
<body>
<h2>Add Student</h2>
<form method="POST">
</form>
<?php
if (isset($_POST['add'])) {
$students = getStudents();
?>
<h3>Student List</h3>
<ul>
</ul>
</body>
</html>
php
CopyEdit
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "school";
?>
php
CopyEdit
<?php
include_once '../config/db.php';
class Student {
private $conn;
$this->conn = $db;
return $result;
return $stmt->execute();
?>
php
CopyEdit
<?php
include_once '../business/Student.php';
include_once '../config/db.php';
// Add student
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$student->addStudent($_POST['name'], $_POST['email']);
$students = $student->getAllStudents();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Student Management</title>
</head>
<body>
<form method="POST">
</form>
<h2>All Students</h2>
<ul>
</ul>
</body>
</html>
7) Developing a fully functional Web Service Application using all the technologies learned in
this course.
pgsql
Copy
Edit
/webservice-app
┣ config/
┣ api/
┃ ┗ user.php → REST API for User Management
┣ business/
┣ public/
┣ assets/
┗ js/
sql
Copy
Edit
USE webapp;
php
Copy
Edit
<?php
include_once '../config/db.php';
header("Content-Type: application/json");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$data = json_decode(file_get_contents("php://input"));
$email = $data->email;
$password = $data->password;
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result()->fetch_assoc();
if ($result && password_verify($password, $result["password"])) {
} else {
?>
php
Copy
Edit
<?php
class User {
private $conn;
$this->conn = $db;
?>
php
Copy
Edit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h2>Login</h2>
<form id="loginForm">
<button type="submit">Login</button>
</form>
<p id="response"></p>
<script src="../js/script.js"></script>
</body>
</html>
javascript
Copy
Edit
e.preventDefault();
method: "POST",
});
document.getElementById("response").innerText = result.message;
});
css
Copy
Edit
body {
text-align: center;
margin-top: 50px;
input, button {
display: block;
padding: 10px;
4. Open http://localhost/webservice-app/public/index.php.