Why are variables for authentication set on HTTP pages but not on HTTPS pages in PHP?

Variables for authentication should not be set on HTTP pages because HTTP is not secure and data sent over it can be intercepted by malicious actors. On the other hand, HTTPS encrypts the data being transmitted, providing a secure connection. Therefore, it is recommended to set variables for authentication on HTTPS pages to ensure the security of sensitive information.

<?php
// Set authentication variables on HTTPS pages only
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){
    $username = 'example_username';
    $password = 'example_password';
    // Additional authentication logic here
} else {
    die("Authentication variables should only be set on secure HTTPS pages.");
}
?>