What are the potential consequences of having duplicate content on a PHP website for SEO?

Having duplicate content on a PHP website can harm your SEO efforts as search engines may penalize your site for having duplicate or low-quality content. To solve this issue, you can implement canonical tags or set up 301 redirects to indicate the preferred version of the content to search engines.

<?php
// Redirect to the preferred version of the content
if ($_SERVER['REQUEST_URI'] == '/duplicate-page') {
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: https://www.example.com/preferred-page');
    exit();
}
?>