Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 would like to add cookie information to my Apache access logs ie: email, username (the cookie is created by php file, not Apache).

Can I add something to log.conf file similar to: \"%{cookieName}i\" to

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

If that doesn't work, do I use cookie log and combine it with access log and how?

share|improve this question

migrated from Aug 2 '09 at 6:42

This question came from our site for professional and enthusiast programmers.

There are three ways to get cookies into Apache logs:

This will match the named cookie sent in the request by the browser but not any other cookies.

This will log the entire Cookie: header sent to the server in the request. This can be quite extensive if many cookies are set or if any of the cookies have a lot of data.

This will match the entire Set-Cookie: header sent by the server in the response.

Note that "cookiename" should be replaced with the name of the cookie you want to log whereas the other two methods should be placed in your CustomLog directive exactly as written. These two are matching headers in the request and the response respectively. They can be used to match any header, not just the cookie headers.

share|improve this answer

try this in your vhost configuration:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\"" with_cookies
CustomLog /var/log/apache2/my-access.log with_cookies

worked for me ; output in my-access.log: - - [02/Aug/2009:12:31:30 +0200] "GET /ct/ HTTP/1.1" 200 - "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv: Gecko/20090715 Firefox/3.5.1" "c1=1; c2=2; PHPSESSID=6c4513f22852a235b8988da822f89d04"
share|improve this answer

Your Answer


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