What potential risks are associated with sending form data over HTTP instead of HTTPS?

Sending form data over HTTP instead of HTTPS can expose sensitive information to potential attackers who could intercept the data. This can lead to data breaches, identity theft, and other security risks. To mitigate this risk, it is important to always use HTTPS when transmitting sensitive information over the internet.

// Redirect to HTTPS if the current request is not secure
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off") {
    $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    header("Location: $redirect");
    exit();
}