Generalized cookie function to set cookie