What server settings or PHP scripts can be used to enable HTTPS for increased security?

To enable HTTPS for increased security, you can configure your server settings to use an SSL certificate. Additionally, you can force all traffic to use HTTPS by redirecting HTTP requests to HTTPS using PHP scripts.

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