How does Google's preference for HTTPS affect the SEO ranking of PHP websites?

Google's preference for HTTPS can positively impact the SEO ranking of PHP websites by improving security and trustworthiness. To ensure that your PHP website ranks well in search results, it is recommended to implement HTTPS to encrypt data transmitted between the server and the user's browser.

<?php
// Redirect to HTTPS if not already using it
if($_SERVER['HTTPS'] != 'on'){
    $redirect_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    header("Location: $redirect_url");
    exit();
}
?>