PHP supports functions such as EXEC(), so if you are on a unix system and you have the proper access rights you should be able to create Symlinks.
I wouldn't use something like javascript to signal the person has left the page, because if I disable javascript.... well you get the idea.
Instead, you'd probably have to write a crontab script to remove "old" links.