PHP hook to load first, before the page loads

I want to add a filter function that is called on page load in PHP. For example, I would like to check some argument before the page is loaded. It must be able to check some $_SESSION ['somearg'] variable.