I have the following code to display the currently logged in user in my application. The strange thing is intermittantly on odd occasions while the user is browsing from one page to another the username of the logged in user changes to another user who is in the database. Logging out and logging back in then displays the current username.
<? if ($sf_user->isAuthenticated()){?>
<div id="welcome">
You are signed in as <strong><?php echo sfContext::getInstance()->getUser()->
getGuardUser()->getName()?></strong> <a href="/logout" class="button">Logout</a>
</div>
<div class="clear"></div>
<? } ?>
Any ideas what could be causing thing?
I can confirm both users were logged in on the same day but at different locations.
Use $sf_user
in your views instead sfContext
Like:
<? if ($sf_user->isAuthenticated()){?>
<div id="welcome">
You are signed in as <strong><?php echo $sf_user->getName()?></strong> <a href="/logout" class="button">Logout</a>
</div>
<div class="clear"></div>
<? } ?>