What are the best practices for checking if a client is using the HTTPS protocol in PHP?

To check if a client is using the HTTPS protocol in PHP, you can use the $_SERVER superglobal variable to access the 'HTTPS' key. If the value is set to 'on', then the client is using HTTPS. This information can be useful for enforcing secure connections or redirecting users to HTTPS pages.

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){
    echo 'Client is using HTTPS';
} else {
    echo 'Client is not using HTTPS';
}