Forum Discussion
Pradeep_Kandala
Sep 13, 2012Nimbostratus
Cookie Enabled/disabled
Can we check in browser weather the cookies are enabled or disabled ?? using IRules ?
If yes .. whats the code ??
Pradeep
- Kevin_StewartEmployeeCookie detection is usually left to client side Javascript and the browser's Document Object Model. Here's just one example of many for doing this: https://github.com/Modernizr/Modernizr/issues/191.
when HTTP_REQUEST { if { ( [HTTP::uri] starts_with "/cookietest" ) } { test for cookie if { not ( [HTTP::cookie exists "COOKIETEST"] ) } { cookies are disabled HTTP::respond 200 content "Sorry. This site requires cookies" } else { cookies enabled - redirect to first URI HTTP::respond 302 Location [findstr [HTTP::uri] "/cookietest" 11] } } elseif { [HTTP::cookie count] == "" } { no cookies (could be first request) - redirect to cookie test URI with test cookie HTTP::respond 302 Location "/cookietest[HTTP::uri]" "Set-Cookie" "COOKIETEST=1" } }
- Pradeep_KandalaNimbostratus
It means I need to write a code under cookietest for cookie checking ?? and iRules dosn't have any directly ryt ??
- Kevin_StewartEmployeeThe problem is really WHERE you're doing the checking. JavaScript on the client side has direct access to the Document Object Model. From the BIG-IP, or ANY server side language, you have to perform a remote test - send a cookie and see if it gets returned. Plus, the stateless nature of HTTP requires that you have some mechanism, in this case other than cookies, to track a specific request/user process. If you send the user a cookie as part of your test, but don't have a way to identify that user as a returning request, you could end up in a loop. The above code very simply uses the /cookietest URI as the persistence mechanism. If you needed to allow users to access without cookie support, you'd need to build in another persistence/session tracking mechanism - like source address or query string.
- Pradeep_KandalaNimbostratus
Thankyou :)
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