Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Feb 23 '12 at 12:54

This question came from our site for pro webmasters.

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_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


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.