Wen Hsiao
Wen Hsiao

Reputation: 631

How to check whether a cookie exists or not?

How to check whether a cookie exists or not? I tried several way but in vain.

if ($cookie__id = "-" ){
    return 302 http:/cookie_sync_server/sync
}
empty_gif

I would like to do cookie sync if there is no cookie exist.

I tried $cookie__id = "-" $cookie__id = 0 $cookie__id = false $cookie__id = "" , all of them are not work.

Upvotes: 4

Views: 3169

Answers (1)

JosMarRivera
JosMarRivera

Reputation: 533

You can do this:

if ($cookie__id){

Be careful if you use "if" in location context. More information:

https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/

Upvotes: 2

Related Questions