3v4l.org

run code in 300+ PHP versions simultaneously
<?php function encrypt_decrypt($action, $string, $secret_key, $secret_iv) { $output = false; if (!extension_loaded('openssl')) { return $string; } $encrypt_method = "AES-256-CBC"; // hash $key = hash('sha256', $secret_key); // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning $iv = substr(hash('sha256', $secret_iv), 0, 16); if($action == 'encrypt') { $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else if($action == 'decrypt'){ $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; } echo encrypt_decrypt('decrypt', 'NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=', ENCRYPTION_KEY, ENCRYPTION_VI);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1 - 8.4.2
Fatal error: Uncaught Error: Undefined constant "ENCRYPTION_KEY" in /in/p0m5m:26 Stack trace: #0 {main} thrown in /in/p0m5m on line 26
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' (this will throw an Error in a future version of PHP) in /in/p0m5m on line 26 Warning: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' (this will throw an Error in a future version of PHP) in /in/p0m5m on line 26 NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Notice: Use of undefined constant ENCRYPTION_KEY - assumed 'ENCRYPTION_KEY' in /in/p0m5m on line 26 Notice: Use of undefined constant ENCRYPTION_VI - assumed 'ENCRYPTION_VI' in /in/p0m5m on line 26 NElmZ1VlbnhCOXQ4eVlPelI2YWtQbm9MWlZSeU5jV1VZSFJhY0NHc2dSWT0=

preferences:
56.67 ms | 409 KiB | 5 Q