It doesn't matter what you use, you'd still have to do it that way. Javascript can't detect cookies any better than PHP can.
That is the only way, set a cookie, then redirect and check for the cookie.
Pass a parameter to your script, and check for it, that way you know that you already tried to set the cookie. This way, if the cookie didn't set, you won't cause and infinite loop.