What is the difference between running PHP as CGI or as a module in terms of HTTP authentication?

When running PHP as a CGI, HTTP authentication headers are not directly accessible to PHP scripts. However, when running PHP as a module, these headers are available through the $_SERVER superglobal array. To access HTTP authentication information when running PHP as CGI, you can parse the Authorization header manually.

// Retrieve HTTP authentication information when running PHP as CGI
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
    list($type, $data) = explode(' ', $_SERVER['HTTP_AUTHORIZATION'], 2);
    $auth_data = base64_decode($data);
    list($username, $password) = explode(':', $auth_data, 2);
    
    // Use $username and $password for authentication
}