Every page at the top (after proper initialization of the session & configurations, whatever preliminary & important you require), you need to fire one function (for example, "checkLogin()") to check & see whether the visiting user has got its session / cookie / permission (for that page) set, according to some specific conditions.
To check what all permissions are required for each specific page, you can pass some parameters regarding these permissions to the function definition, and authenticate the user as suitable.
If the condition(s) are set, you can redirect the user as an authenticated one to his requested page, otherwise just redirect him to your site's login page (with his requested page mentioned either in the query string or saved in a session variable). Now after proper login & setting of specific permissions for authentication, you can easily use the query string's value of requested page to redirect him to his destination.
Hope it helps.