I'm building a Magento sandbox environment and need to set a session cookie based on a value in the query-string. The value in the query-string will be used to set an account ID for another service used within this Magento environment. This is not a production, public facing environment, so security is not a concern.
My first challenge is figuring out where to actually place the code within the Magento MVC. All users accessing this system will come directly through the root domain (as opposed to a specific page within the site... say a product or product category page). The bookmarked URL will look something like this:
http://www.somedomain.com/index.php?accountID=12345678
Below is the initial code I wrote to evaluate the query-string and set the cookie value:
$account_id = $this->getRequest()->getParam('accountID'); $account_id_cookie = Mage::getSingleton('core/cookie'); $account_id_cookie->set('account_id',$account_id,time()+86400,'/');
Where is the best place to put this code within the Magento MVC? I tried the root index.php
file but it doesn't work. I suspect the best place is within a controller but I'm not sure which controller file is appropriate.
Once this value is set within a session cookie, it will be referenced in a JavaScript snippet located within the footer of the site so it's necessary for the value to be present in the cookie prior to the footer include being parsed.