Brazzer's does something similar. A simple way would be using PHP sessions.
If you want it to carry over if a user exits your site and comes back later, you'd need MySQL logging by IP.
I can do something simple and functional for you, using javascript. ICQ me if you're interested in making a deal

565982359