What are some best practices for implementing framebusters in PHP?

Framebusters are used to prevent a webpage from being framed within another site, which can be a security risk. To implement a framebuster in PHP, you can use JavaScript to check if the page is being framed and redirect if necessary.

<?php
echo '<script type="text/javascript">
    if (top != self) {
        top.location.replace(self.location.href);
    }
</script>';
?>