What are the best practices for handling sensitive data in PHP URLs?

Sensitive data should never be passed through URLs in plain text as they can be easily accessed and viewed by unauthorized users. One way to handle sensitive data in PHP URLs is to encrypt the data before passing it in the URL and decrypt it on the receiving end.

// Encrypting sensitive data before passing it in the URL
$sensitiveData = "mySensitiveData";
$encryptedData = openssl_encrypt($sensitiveData, 'AES-256-CBC', 'mySecretKey', 0, 'mySecretIV');
$encodedData = urlencode(base64_encode($encryptedData));

// Passing the encrypted data in the URL
$url = "http://example.com/page.php?data=" . $encodedData;

// Decrypting the data on the receiving end
$decodedData = base64_decode(urldecode($_GET['data']));
$decryptedData = openssl_decrypt($decodedData, 'AES-256-CBC', 'mySecretKey', 0, 'mySecretIV');
echo $decryptedData;