Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

migrated from webmasters.stackexchange.com Feb 23 '12 at 12:54

This question came from our site for pro webmasters.

1 Answer 1

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:a@example.com,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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.