in reply to Setting cookie code...

updated:

I guess the problem might be that you set $cookie to a new cookie object with $cookie as the value of $cookie.

Your code might confused about what's in $cookie.