You can place the code wherever you would like the message to appear. It all depends on if your login redirects users or uses a single file for processing, or where the user is redirected to on success.
As for the code, it can be done with an if statement
if( isset($_SESSION['username']) )
{
print 'Welcome ' . $_SESSION['username'] . '.';
}