What role does the use of SESSION variables play in maintaining order number consistency in PHP when dealing with customer orders?

When dealing with customer orders in PHP, maintaining order number consistency is crucial to avoid duplicate or incorrect orders. One way to achieve this is by using SESSION variables to store and track the order number throughout the ordering process. By assigning a unique order number to each customer session, you can ensure that each order is properly identified and processed.

// Start or resume the session
session_start();

// Generate a unique order number
$order_number = uniqid();

// Store the order number in a SESSION variable
$_SESSION['order_number'] = $order_number;

// Retrieve the order number from the SESSION variable
$order_number = $_SESSION['order_number'];