You cannot prevent a user from going back to the login page. The only thing you can do is like you indicated, checking if the user is logged in. What is there that doesn't work in your example? Have you registerd the $username variable properly? Is there a session being made (check your session directoy, which one is depending on your os and php settings; if you use a database for your sessions, check the database)