Forum Discussion

Jason_LaRocque_'s avatar
Jason_LaRocque_
Icon for Nimbostratus rankNimbostratus
Jan 26, 2007

Checking if cookie exists on HTTP_RESPONSE

Good Morning-

 

We're looking to remove Apache servers from our DMZ in favor of other technologies (not apache based). However, we do unique user tracking with MOD_TRACKING in apache that inserts a SANE cookie. This cookie is used to identify uniqueness of visitors and track their usage of the site.

 

 

QUESTION:

 

I'm inserting a cookie on response that is a combination of source IP and current time in clock seconds. This part seems to work. The part that fails is the check to see if the cookie exists (naturally I don't want to insert the cookie if it exists in order to keep the original value).

 

 

Here's the rule:

 

 

when HTTP_RESPONSE {

 

set currtime [clock seconds]

 

set clientip [IP::client_addr]

 

set cookieval [concat $clientip-$currtime]

 

 

if {[HTTP::cookie exists "trackcookie"] == 1} {

 

}

 

 

elseif {[HTTP::cookie exists "trackcookie"] == 0} {

 

HTTP::cookie insert name "trackcookie" value $cookieval path / domain .mydomain.com

 

HTTP::cookie expires "trackcookie" 3000 relative

 

}

 

}

 

 

Any ideas?

 

Thanks everyone!!

 

Jason

 

  • If I understood correctly, you want to set the cookie if it isn't found in the request received from the user. What you're actually doing is checking whether it is present in the response being sent back from the server, which, of course, it never is.

    You should check for the existence of the cookie in the HTTP_REQUEST event, not HTTP_RESPONSE. What you want is most likely this:

    when HTTP_REQUEST {
      set isset [HTTP::cookie exists {trackcookie}]
    }
    when HTTP_RESPONSE {
      if {$isset == 0} {
        HTTP::cookie insert name {trackcookie} value "[IP::client_addr]-[clock seconds]" path {/} domain {.mydomain.com}
        HTTP::cookie expires {trackcookie} 3000 relative
      }
    }