Forum Discussion
Brent_Sachnoff_
Nimbostratus
Dec 06, 2007Assigning cookies only once
I'm trying to assign a client a cookie that will be psuedo random using:
when HTTP_RESPONSE {
expr srand([clock clicks])
set tracker [expr (rand() * 999) + 10]
HTTP::cookie insert name tracker value $tracker path "/"
}
This works fine and I can verify it on the HTTP_REQUEST. My problem is I only want to assign this cookie once and never do it again for this particular session. Is there a way to:
on request, check for cookie. If it does not exist, on response issue one out otherwise just log the current cookie.
Thanks,
Brent
- hoolio
Cirrostratus
You can use a local variable to track whether the cookie was presented in the client request:when HTTP_REQUEST { if {[HTTP::cookie exists tracker]}{ set need_cookie 0 log local0. "tracker cookie=[HTTP::cookie value tracker]" } else { set need_cookie 1 } } when HTTP_RESPONSE { if {$need_cookie] }{ expr srand([clock clicks]) set tracker [expr (rand() * 999) + 10] HTTP::cookie insert name tracker value $tracker path "/" } }
- Brent_Sachnoff_
Nimbostratus
I was trying to use a local variable set as the actual cookie if it existed and then checking that on the response.. For some reason I had no luck. This does work now though. Thanks! - Joe_Hsy_45207
Nimbostratus
Hi Aaron, - Joe_Hsy_45207
Nimbostratus
Just realized that the cookie insert code will not be executed for each http hit (only the first hit for that browser session), so performance shouldn't be too much of an issue. Never mind!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects