私は簡単ですが信頼できない方法を念頭に置いています:
次のようにSessionvarを設定します
$_SESSION['user_already_on_page'] = true;
これで、この変数をチェックして、エラー ページなどを返すことができます。
if($_SESSION['user_already_on_page'])
{
//maybe the user has left unexpected. to workaround this we have to check
//for the last db entry. Examplecode:
$query = mysql_query($_db,'SELECT LastUpdated FROM Pointstable WHERE U_Id = $uid');
$row = mysql_fetch_array($query);
if((time()-$row['LastUpdated']) < 5)
{
die("You are already on this page!");
}
//$_SESSION['user_already_on_page'] is set but the last update is older than 5 sec
//it seems, that he unexpectedly lost connection or something like that.
}
この変数の設定を解除するには、ページを閉じるときにこの変数の設定を解除する AJAX スクリプトを起動できます。unsetonpage.ajax.phpは次のようになります。
<?php $_SESSION['user_already_on_page'] = false;?>
そしてあなたの JS-Part (jquery を使用):
$(window).bind('beforeunload', function(eventObject) {
$.ajax({url:'./ajax/unsetonpage.ajax.php',type:'GET'});
});
これはうまくいくはずです。