Forum Discussion

Sam_Parkes_1110's avatar
Sam_Parkes_1110
Icon for Nimbostratus rankNimbostratus
Dec 04, 2009

check if browser's cookies are enabled

Hi I've been looking through the forums, but cant find a way of using the F5 to check if a browser's cookies are enabled before continuing to serve requests to it? Is there a way of doing this with an iRule? Apologies if this has already been written in the forum somewhere.

 

Thanks,

 

Sam.

4 Replies

  • Hi Sam,

     

     

    If you can figure out how you want to test whether clients support session and/or persistent cookies you could probably use an iRule which sends the HTML and parses the subsequent requests. Here are a few examples found searching for 'check browser cookies enabled':

     

     

    http://techpatterns.com/downloads/javascript_check_cookies.php

     

     

    http://www.html-kit.com/tools/cookietester/

     

     

    http://www.velocityreviews.com/forums/t73185-detect-if-cookies-are-enabled.html

     

     

    The way this is done on Microsoft Office Online is that we have a page which

     

    tries to set a session cookie and a permanent cookie; this page then

     

    redirects to a page which tests for those cookies. If they're not both

     

    present, that page then redirects to a "you need to enable cookies" error

     

    page.

     

     

    You can send the HTTP response using HTTP::respond and check for cookies in the request using HTTP::cookie exists.

     

     

    Aaron
  • Thanks Aaron,

     

    I've got something working for now:

     

    when HTTP_REQUEST {

     

    if { ([HTTP::uri] starts_with "/landingPage.form") and [HTTP::cookie exists "cookies"] } {

     

    return

     

    }

     

    elseif { [HTTP::uri] starts_with "/landingPage.form" } {

     

    HTTP::respond 301 Location "http://my.domain.com/landingPage.form" Set-Cookie cookies=true

     

    }

     

    }

     

    This is working for now, our developers are working on a permanent solution based on a 2-stage redirect like you suggested, the only problem with this is the looping done if a browser disables cookies, but at least it protects our application layer.

     

    Thanks again.

     

    Sam.
  • That's a good start. If you used two pages you could have one set the cookie and then other allow access if the client presents the cookie(s) or send a redirect/HTTP response for clients who don't have a cookie. And by "pages" it could just be two different HTML responses sent from the iRule.

     

     

    Aaron