Add new set_cookie() method

In order to make the session cookie easier to adjust, and to prevent duplicate code, I've added a new set_cookie() method that is then used in `regenerate_id()` and `__construct()`.