title: Play framework how do sessions and cookies work?
body: <p>How does play validate a cookie?<br/></p>
  
  <ul>
  <li>I noticed that after I restarted the server I was still logged in even though I
  don't presist any session data in the database.<br/> </li>
  <li>I also noticed
  that I could set the date on the server to be larger that the exipry
  date of the cookie and still I was logged in.<br/> </li>
  <li>I logged out
  (saved the cookie to a text file) and the browser lost the cookie. Then I
  recreated the cookie from the text file and I was logged in again.</li>
  </ul>
  
  <p>The cookie looks like this:</p>
  
  <p>PLAY_SESSION=e6443c88da7xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-userid%3A1</p>
  
  <pre><code>// My logout code
  def logout() = Action {
    Ok("").withNewSession
  }
  </code></pre>
  
  <hr>
  
  <p><a href="https://github.com/playframework/Play20/wiki/ScalaSessionFlash">From the documentation</a><br>
  <strong>Discarding the whole session</strong><br>
  There is special operation that discards the whole session:</p>
  
  <pre><code>Ok("Bye").withNewSession
  </code></pre>