views:

26

answers:

1

Hi,

I'm trying to pass the value of a cookie to a bash script:

RewriteCond %{HTTP_COOKIE} mycookie=(.*) [NC]
RewriteRule .* script.sh?cookievar=%1

... but can't seem to find out how to read the GET variable in the bash script. (I suppose I'm asking Google the wrong queries, but can't find any info on this).

Is this even possible, and if so, please how?

Thanks, David

A: 

You have to look at QUERY_STRING environment variable in Bash in order to access GET variables. In your case it should be set to cookievar=VALUE. To extract a variable's value, use something like this:

COOKIEVAR=$(echo ${QUERY_STRING} | sed -n -e 's/^.*cookievar=\([^&]*\).*$/\1/p' -e 's/%20/ /g')

Good luck!

Vlad Lazarenko
Thank you Vlad, I'll give that a try!
David