What potential security risks are associated with using PHP sessions to store sensitive data like shopping cart contents?

Storing sensitive data like shopping cart contents in PHP sessions can pose a security risk if the session data is not properly secured. To mitigate this risk, sensitive data should be encrypted before being stored in the session.

// Encrypt sensitive data before storing in session
$encryption_key = "your_encryption_key_here";
$sensitive_data = "your_sensitive_data_here";

$encrypted_data = openssl_encrypt($sensitive_data, 'AES-256-CBC', $encryption_key, 0, 'your_iv_here');

$_SESSION['encrypted_data'] = $encrypted_data;