I am not sure where to place this code, because you can set a redirect in your login module. You can redirect to whatever article you want. But if you want to control this, you have to include the session variable inside your redirected article - or my suggestion, include it when you need it.
No matter what, the variable is stored in a session and it is accessable on what page you want. The session variable is killed once you close all of your browser windows/sessions.