What potential issues can arise when working with cookies in PHP?

One potential issue when working with cookies in PHP is that they can be easily manipulated by users, leading to security vulnerabilities. To mitigate this risk, it's important to encrypt sensitive data stored in cookies to prevent tampering.

// Encrypting sensitive data before storing it in a cookie
$secretKey = 'mySecretKey';
$data = 'sensitiveData';
$encryptedData = openssl_encrypt($data, 'AES-256-CBC', $secretKey, 0, 'myInitializationVector');
setcookie('encryptedData', $encryptedData, time() + 3600, '/');