setCookie only works on repeat call?

I get an unexpected behavior using setCookie as it seems to only apply to the repeat call but not the first call?

The script I use look like this:
setCookie ta=img

The expected result is that the same image should be displayed in both first and repeat view, but the image differs between them.


I would have through that the cookie would be set already at the first call but it does not seem to be the case? I have seen suggestions to set an authentication cookie using setCookie and would think that this feature should work. Or am I doing something wrong?

Has anybody seen this problem or have any ideas?