What are the best practices for handling the generation and display of unique order numbers in a PHP shop system?

To handle the generation and display of unique order numbers in a PHP shop system, it is best practice to use a combination of timestamp and random characters to create a unique identifier for each order. This helps to ensure that order numbers are unique and not easily guessable. Additionally, storing the generated order number in the database along with the order details allows for easy retrieval and tracking.

// Generate a unique order number
function generateOrderNumber() {
    $timestamp = time();
    $random = bin2hex(random_bytes(4)); // Generate random 8-character hexadecimal string
    $orderNumber = $timestamp . $random;
    
    return $orderNumber;
}

// Display the unique order number
$orderNumber = generateOrderNumber();
echo "Your order number is: " . $orderNumber;