Best place check URL and set cookie

I need: check URL and set cookies if URL contains some GET-parameters.

For example:

if ( isset($_GET['param1']) )


    setcookie('param1',$_GET['param1'],strtotime('+1 minutes'));


What is the best place in framework to do this?

I have tried use parseUrl method of HttpRequest class, but method is called twice (may be because I have application builded by this way

I can do this in main layout (views/layout/main.php), but it is wrong way I seems.