Cookie Server Variable?

Topics: Developer Forum, User Forum
Apr 12, 2007 at 11:59 PM
Is there any ability to check for the existence of a cookie? I'd like to see if a cookie exists prior to allowing direct access to file for downloading. If the cookie doesn't exists, I'd like to forward them to a licensing page where they agree to a waiver, receive a temporary cookie and then are allowed non-redirected access to the files.

I'm imagining that it would look like this for a particular domain:
RewriteCond %{SERVER_NAME} ^www.myserver.com(.*)$ I
RewriteCond %{COOKIE} (?!.IAGREE.) I
RewriteRule ^/download/.* /license.txt I

Thanks.
Aug 21, 2009 at 3:31 PM

Did you ever receive a response to this? I am looking to detect a cookie as well.

Coordinator
Aug 21, 2009 at 3:43 PM
Edited Aug 21, 2009 at 3:44 PM

There was never a response, but here's the answer: you can examine the server variable "HTTP_COOKIE".

  # check for existence of the cookie, before allowing download
  RewriteCond %{HTTP_COOKIE} (?!LicenseAcceptance=.+)   [I]
  RedirectRule ^/download/.*  /license.php?path=$0      [I,L]

The redirect fires if the LicenseAcceptance cookie is not present, and if a download URL has been requested. In that case the request gets redirected to the license page, passing the original URL path, too. That page presents a "I accept" button. Once the button is clicked, the license page sets the cookie, and redirects back to the original download path, which should now succeed.  You could also make it a Rewrite instead of a Redirect. 

 

Aug 21, 2009 at 3:53 PM

Thanks thats what i needed. I didn't see that in the IIRF docs but its exactly what i needed.

 

 

Mar 11, 2010 at 4:37 PM

Hi. I can't get this to work. What value in the cookie is the rule looking for? In my case, the cookie is storing a UserID value (integer). No matter what I try, the following rule always evaluates true (as seen in the iirf log):

RewriteCond %{HTTP_COOKIE}         (?!UserID.+)            [I]

The actual contents of the cookie are:

 

UserID
%2D1
cas.lablynx.com/
1024
3727591424
30065056
2823749136
30064959
*

UserID

%2D1

mydomain.com/

1024

3727591424

30065056

2823749136

30064959

*

Thanks for any help!!

 

Coordinator
Mar 11, 2010 at 11:20 PM

Start a new thread.