What are the alternative methods to base64_encode for encrypting variables in PHP?

If you want to encrypt variables in PHP without using base64_encode, you can consider using other encryption methods such as openssl_encrypt or mcrypt_encrypt. These functions provide more robust encryption mechanisms compared to base64_encode. By using these functions, you can ensure that your data is securely encrypted and can only be decrypted with the corresponding decryption function.

// Using openssl_encrypt to encrypt a variable
$data = 'secret data';
$key = 'my_secret_key';
$method = 'AES-256-CBC';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));

$encrypted = openssl_encrypt($data, $method, $key, 0, $iv);

echo $encrypted;