How can PHP sessions be utilized to store and retrieve product data for display on different pages?

To store and retrieve product data for display on different pages using PHP sessions, you can store the product information in a session variable when the user adds a product to their cart. Then, on each page where you need to display the product information, you can retrieve the data from the session variable.

// Start the session
session_start();

// Add product data to session when user adds a product to cart
$_SESSION['product'] = [
    'name' => 'Product Name',
    'price' => 19.99,
    'description' => 'Product Description'
];

// Retrieve product data from session on different pages
if(isset($_SESSION['product'])) {
    $product = $_SESSION['product'];
    echo $product['name'];
    echo $product['price'];
    echo $product['description'];
}