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_Stewart
Sep 13, 2012Employee
Cookie 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.
The problem with performing this test server side is twofold: you have to set a cookie and see if it gets returned, and also maintain some persistence mechanism OTHER THAN cookies while testing. So a legitimate code example for your request depends on:
1. what you can use for persistence if cookies aren't supported (source IP, SSL session ID, etc.)
2. what you would do if cookies are disabled (terminate the session, manipulate the URI, etc.)
In case you just want to close the connection and let them know the site requires cookies, the following may work for you:
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"
}
}
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