Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set Environment variable as cookie (apache)

Tags:

cookies

apache

i am trying to set the cookies value to a environment variable. Which is a country code. Part of the configuration as below.

MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /etc/apache2/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code

Want to set the cookie name "CC" value to "MM_COUNTRY_CODE" from above. i have tried the below but getting a NULL.

SetEnvIf Cookie "cccookie=([^;]+)" MM_COUNTRY_CODE=$1
Header set Set-Cookie "CC=%{CCCOOKIE}e;path=/;Expires=MI3600" env=MM_COUNTRY_CODE

any suggestions ?

like image 379
Arshad Zackeriya Avatar asked Feb 05 '26 17:02

Arshad Zackeriya


1 Answers

You can replace below lines

SetEnvIf Cookie "cccookie=([^;]+)" MM_COUNTRY_CODE=$1
Header set Set-Cookie "CC=%{CCCOOKIE}e;path=/;Expires=MI3600" env=MM_COUNTRY_CODE

with this below line

Header add set Set-Cookie "CC=%{MM_COUNTRY_CODE}e"

'%{MM_COUNTRY_CODE}e' The contents of the environment variable MM_COUNTRY_CODE.notice the 'e'.

like image 150
Arshad Zackeriya Avatar answered Feb 07 '26 07:02

Arshad Zackeriya