19. 09.
Every website needs statistics, but finding, improving (or killing!) website’s ‘dead zones’, needs some cooler data than screen resolution, Os, search engines terms or Java support…
Lighttpd logging features help us, saving user’s session id into access log file: all you need to do, is setting a ‘X-LIGHTTPD-SID’ http response header containing user session id, and a proper Lighttpd log format; for example:
accesslog.format = “%h %V %u %t \”%r\” %b %>s \”%{Referer}i\” \”%{User-Agent}i\” \”%{X-LIGHTTPD-SID}o\”"
This is cool, because
- Lighttpd won’t send ‘X-LIGHTTPD-*’ header to user’s browser (so you’ll be able to silenty track them)
- You’ll be able to have a background process to parse and elaborate access log file, and rebuild a ’session’ link path (if your website makes 10.000 pageviews per minute, i don’t think you want to make 10.000 insert per minute into DBs to store statistics!)
Setting custom headers with php is really easy:
session_start();
header("X-LIGHTTPD-SID: ".session_id());
?>
… but we love Ruby On Rails!
So, let’s open you application controller, and add these few lines:
class ApplicationController < ActionController::Base
# Pick a unique cookie name to distinguish our session data from others'
session :session_key => ‘_test_session_id’after_filter :track_sid
def track_sid
response.headers["X-LIGHTTPD-SID"] = session.session_id
endend
Now enjoy session ids into acces log:
127.0.0.1 eureka.marco-borromeo.com:3000 - [18/Sep/2007:19:18:19 +0200] “GET /test HTTP/1.1″ 65 200 “-” “Mozilla/5.0 (Macintosh; U; Intel Mac OS X; it-it) AppleWebKit/419.3 (KHTML, like Gecko) Safari/419.3″ “ecac8b15812c47bf3fa9d8022d293a09″
… and happy session click path rebuilding!










Marco Borromeo