Well, browser headers aren't terribly reliable, and can be spoofed easily, so make sure you're not using this for any kind of authentication/security. Generally, I'm always using some kind of a template that gets included on every page. I'd just put something in that. If not, you could have a separate script that checks the referrer that is included on each page.
You didn't even mention what language you're using, but the pseudo-code would look something like this:
1. check the HTTP_REFERER
2. if it's not from your site, log it or do whatever.
It depends on what your site is written in, but most languages have an ability to get at the HTTP_REFERER in the header. For example, if you wanted to get at it in PHP you would access the server array: