PHP getSession
From Facebook Developer Wiki (FbDevWiki.com)
Logged in vs Logged out: ( not exactly correct as the session can become invalidated by Facebook but getSession will still return the values from the cookie --Wong 01:59, 13 December 2010 (UTC) )
if ($facebook->getSession()) {
echo '<a href="' . $facebook->getLogoutUrl() . '">Logout</a>';
} else {
echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>';
}