Write cookies before page generation, so changes take effect immediately.