How can the $_SERVER array in PHP be utilized to check for HTTPS in a URL?

To check for HTTPS in a URL using the $_SERVER array in PHP, you can access the 'HTTPS' key within the array. If the value is set to 'on', it means the connection is secure using HTTPS. You can use this information to determine if the current URL is accessed via HTTPS.

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
    echo 'This URL is accessed via HTTPS.';
} else {
    echo 'This URL is not accessed via HTTPS.';
}