in reply to Re^4: cookies not getting setup
in thread cookies not getting setup

The Cookie is printed on the browser page

That means that you already printed a header earlier. Don't do that. Print a header only once.