What are some best practices for setting background images on a website using PHP?

When setting background images on a website using PHP, it is important to ensure that the image is properly formatted and located in the correct directory. One best practice is to use CSS to set the background image, as this allows for more flexibility and customization. Additionally, it is recommended to sanitize user input to prevent any security vulnerabilities.

<?php
$background_image = 'path/to/background.jpg';
?>
<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            background-image: url('<?php echo $background_image; ?>');
            background-size: cover;
            background-repeat: no-repeat;
        }
    </style>
</head>
<body>
    <!-- Your website content here -->
</body>
</html>