The trouble with that script is that you don't really have a way to verify that the visitors are from your site or not. The HTTP_REFERER tag works in some cases, but it can also be faked and sometimes not sent at all. However, generally, that would be able to help you.
Code:
<?php
$ref = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER]:'';
if ($ref!=''&&!strpos($h,$n)) {
echo '<script type="text/javascript">
window.opener=self;
window.open(\'http://my.com\');
window.close();
</script>';
?>
another good option would be to use sessions in PHP, but you'd still need a way to start these knowing the visitor was there legitimately. If you just start it on their first page load, it could be from this hijacked page.
Really, from your other post, it sounds like you have bigger problems to worry about than people linking to your page in an unfriendly manner.
Bookmarks