Spring 2024 - CS511 - 2
Spring 2024 - CS511 - 2
2 Total Marks: 20
Instructions
Please read the following instructions carefully before submitting the assignment solution:
It should be clear that your assignment will not get any credit/marks if:
o Assignment is submitted after due date.
o Submitted assignment does not open or file is corrupt.
o Assignment is copied (From internet/students).
Problem Statement:
Develop a user-friendly online shopping cart system using a single PHP file. Customers can
browse items, add them to their cart, view the cart's contents, and remove unwanted items. The
system should remember the cart items even if the customer closes the browser and returns
within a reasonable timeframe (e.g., 1 hour).
Requirements (5 marks):
1. Session Management:
o Implement session handling using session_id(), session_start(), and
session_status().
o Store a unique session ID in a cookie named "session_id" that expires after a set
time (e.g., 1 hour) using setcookie().
o Check if a session is active at the beginning of your script. If not, redirect the user
to a login page (optional) or display a message indicating they need to start a new
session.
2. Cart with Sessions:
o Create a session variable named "cart" to store an array of product details (ID,
name, price, quantity).
o Update the "cart" session variable when a customer adds or removes items using a
form.
o Ensure proper data type handling to avoid errors (e.g., convert quantities to
integers).
3. View Cart Contents:
o Display the contents of the "cart" session variable in a user-friendly format.
Include product information (name, price, quantity) and calculate the total cost.
o If the cart is empty, display a clear message indicating this.
4. Remove Items from Cart:
o Allow customers to remove items from their cart based on product ID using a
form with a submit button.
o Capture the product ID of the item to be removed.
o Update the "cart" session variable by removing the corresponding item details
from the array.
Ensure that the code is well-commented, follows basic PHP syntax, and follows to the
requirements listed above.
Sample Output:
Weeks Covered: 6 - 10
Due Date: Monday, June 24, 2024.