In the spirit of perl, there are dozens of ways to do it, but the most appropriate depends on the rest of your design.
This question has been answered quite a few times
Jay "Yohimbe" Thorne, alpha geek for UserFriendly
And a tip for those who don't want to accidentally post as
Anonymous Monk. Set your personal theme to anything
other than the site default. Then when you follow
a link that can leave you logged out, you will see
everything change colour and know what happened...