Where do i store username and userid? sessions or cookie?
<p>There are many instances in my code where quick access to the logged in username and userid is needed.  I currently use cookies.  This isn't secure.</p>

<p>I thought sessions would be a solution but sessions expire.</p>

<p>Another option, is to store a unique token in a cookie and then match with a stored token in the database, to retrieve logged in user data.  This is the most secure solution but the problem i see with this is, there are many times in my code where the logged in username and userid is needed but querying all the time would use up resources unnecessary(is this true?)</p>

<p>What is the solution?</p>
