E Commerce Lab Practicals
E Commerce Lab Practicals
E Commerce Lab Practicals
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="home">
<h2>Home Section</h2>
<section id="about">
<h2>About Us</h2>
</section>
<section id="services">
<h2>Our Services</h2>
</section>
<section id="contact">
<h2>Contact Us</h2>
</section>
</main>
<footer>
</footer>
</body>
</html>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate Name
if (empty($_POST["name"])) {
} else {
$name = sanitize_input($_POST["name"]);
// Validate Email
if (empty($_POST["email"])) {
} else {
$email = sanitize_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
function sanitize_input($data) {
return htmlspecialchars(stripslashes(trim($data)));
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<br><br>
<br><br>
</form>
</body>
</html>
2. Validating a Password
You can also implement password validation to ensure that users create strong passwords:
<?php
$passwordErr = "";
$password = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["password"])) {
} else {
$password = sanitize_input($_POST["password"]);
$passwordErr = "Password must be at least 8 characters long and include letters and
numbers";
function sanitize_input($data) {
return htmlspecialchars(stripslashes(trim($data)));
?>
<br><br>
$products = [
'id' => 1,
],
'id' => 2,
],
'id' => 3,
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Product Catalog</title>
</head>
<body>
<div class="container">
<h1>Product Catalog</h1>
<div class="catalog">
<div class="product">
<button>Add to Cart</button>
</div>
</div>
</div>
</body>
</html>
Directory Structure
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<div class="container">
<h2>Login</h2>
<label for="username">Username:</label>
<br><br>
<label for="password">Password:</label>
<br><br>
<button type="submit">Login</button>
</form>
<?php
if (isset($_SESSION['error'])) {
unset($_SESSION['error']);
?>
</div>
</body>
</html>
<?php
session_start();
// Sample user credentials (for demonstration only; use hashed passwords in production)
$valid_username = "admin";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
header("Location: dashboard.php");
exit();
} else {
header("Location: login.php");
exit();
<?php
session_start();
exit();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
</head>
<body>
<div class="container">
<a href="logout.php">Logout</a>
</div>
</body>
</html>
<?php
session_start();
session_unset();
session_destroy();
header("Location: login.php");
exit();
Business Model
Business Model
1. Overview:
o An online platform where customers can browse and purchase a variety of products, such as
electronics, clothing, and home goods.
o Revenue generated through product sales, possibly supplemented by advertisements and affiliate
marketing.
2. Target Market:
o Tech-savvy individuals aged 18-45 who prefer shopping online for convenience and variety.
3. Value Proposition:
Wide selection of products, competitive pricing, convenient shopping experience, and home
delivery.
Revenue Streams:
Product sales
Shipping fees
Affiliate marketing
Advertisements
5.cost Structure:
o Inventory management
Key Functionalities
1. User Registration and Login: Users can create accounts to track orders and manage personal
information.
3. Shopping Cart: Users can add products to their cart and proceed to checkout.
4. Order Management: Users can view their order history and order status.
5. Payment Integration: Allow users to make payments via credit/debit cards or third-party payment
gateways.
Technology Stack
Here are some example code snippets for key functionalities in PHP.
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT); // Hash
password for security
if ($stmt->execute([$username, $password])) {
header("Location: login.php");
exit();
} else {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Register</title>
</head>
<body>
<button type="submit">Register</button>
</form>
</body>
</html>
<?php
session_start();
$products = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Product Catalog</title>
</head>
<body>
<h1>Product Catalog</h1>
<div class="product-list">
<div class="product">
</form>
</div>
</body>
</html>
<?php
session_start();
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = [];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$product_id = $_POST['product_id'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Your Cart</title>
</head>
<body>
<h1>Your Cart</h1>
<ul>
</ul>
<a href="checkout.php">Proceed to Checkout</a>
</body>
</html>