Apache: How do I log values in the cookie environment variable?
I am trying to log the cookie info using
CustomLog $PATH "%{cookie}i"
Now i want the certain variables ex(hb_name, hb_email, hb_cellno, hb_visit, hb_session
) to be logged into my log file from this cookie.
How can I parse out specific values from this cookie and log them?
Well, that completely depends on the format of the cookie - but a little regex should get you there.
Say your cookie's content were hb_name:A,hb_email:[email protected],hb_cellno:1112223333
:
RewriteCond %{HTTP_COOKIE} hb_name:([^,]*)
RewriteRule ^ - [E=HBNAME:%1]
RewriteCond %{HTTP_COOKIE} hb_email:([^,]*)
RewriteRule ^ - [E=HBEMAIL:%1]
RewriteCond %{HTTP_COOKIE} hb_cellno:([^,]*)
RewriteRule ^ - [E=HBCELL:%1]
So that puts each of these values into their own Apache environment variable, which can then be logged easily:
CustomLog /some/file "name=%{HBNAME}e email=%{HBEMAIL}e cell=%{HBCELL}e"
If you can clarify the exact format of your cookie and the exact format you want the log in, then I can be more specific.