What are the potential reasons for a PHP script to work on one server but not on another?

The potential reasons for a PHP script to work on one server but not on another could be differences in server configurations, PHP versions, missing extensions, or file permissions. To solve this issue, ensure that both servers have the same PHP version installed, required extensions are enabled, and file permissions are set correctly.

// Check PHP version
if (version_compare(PHP_VERSION, '7.0.0') < 0) {
    die('PHP version 7.0.0 or higher is required.');
}

// Check for required extensions
$required_extensions = ['pdo', 'mysqli', 'gd'];
foreach ($required_extensions as $extension) {
    if (!extension_loaded($extension)) {
        die('Required extension ' . $extension . ' is not loaded.');
    }
}

// Check file permissions
if (!is_writable('path/to/file.txt')) {
    die('File.txt is not writable.');
}