There should be REMOTE_USER enviroment variable following the original CGI standard.
In this case domain username can be accesable by _SERVER['REMOTE_USER'] in PHP or request.env['REMOTE_USER'] in Ruby on Rails.
It is very important part of SSO-based authentication.
For example mod_spnego and mod_auth_kerb for Apache2 do it.