in order to access any session variables on a page, you have to first activate that session on each page that you want to access it.
session_start();
now if you have logged in someone successfully already, lets assume they have a value in the session to confirm this, for instance $_SESSION['logged'] = true;
so when it comes to the button bit, make sure the page has the session start bit, then do the if statement like this
if($_SESSION['logged'])
{
echo 'logout';
}
else
{
echo 'login'
}