How effective is HTTPS encryption in protecting data from sniffing attacks when storing passwords online in PHP?

When storing passwords online in PHP, it is crucial to encrypt the data to protect it from sniffing attacks. HTTPS encryption provides a secure way to transmit data over the internet by encrypting the communication between the client and server. By using HTTPS, the data, including passwords, is encrypted during transmission, making it difficult for attackers to intercept and decipher the information.

// Enable HTTPS encryption to protect data during transmission
// This code should be placed at the beginning of your PHP script

if ($_SERVER['HTTPS'] != 'on') {
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit();
}