What are the potential pitfalls of incorrectly implementing canonical URLs in PHP websites?

Incorrectly implementing canonical URLs in PHP websites can lead to duplicate content issues, which can negatively impact SEO rankings. To avoid this, make sure that the canonical URL is set correctly to point to the preferred version of the page.

// Set the canonical URL in the head section of your PHP website
$canonical_url = "https://www.example.com/page";
echo '<link rel="canonical" href="' . $canonical_url . '" />';