Are there alternative methods or libraries that can be used to achieve the same functionality as mcrypt_module_open in PHP scripts to avoid compatibility issues across different servers?

The mcrypt extension in PHP has been deprecated since PHP 7.1 and removed in PHP 7.2, leading to compatibility issues across different servers. To avoid these issues, you can switch to using the OpenSSL extension in PHP for encryption and decryption tasks. OpenSSL is widely supported and provides similar functionality to mcrypt.

// Example of using OpenSSL for encryption and decryption
$plaintext = 'Hello, World!';
$key = 'secretkey';

// Encrypt data
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$ciphertext = openssl_encrypt($plaintext, 'aes-256-cbc', $key, 0, $iv);

// Decrypt data
$decrypted = openssl_decrypt($ciphertext, 'aes-256-cbc', $key, 0, $iv);

echo $decrypted; // Output: Hello, World!