You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Henri Schomäcker <he...@virtual-homes.de> on 2005/03/22 13:08:04 UTC

no results with apr_env_get

Hi folks,

I have a problem getting the environment variables with apr_env_get in 
the request handler of my module.
What I need are HTTP_USER_AGENT and REMOTE_ADDRESS but I just don't get 
anything as a resullt in my char*.

Here's the code:
8<--------8<--------8<--------8<--------8<--------8<--------8<--
char* chUserAgent;*
if* (apr_env_get(&chUserAgent, "HTTP_USER_AGENT", r->pool) == APR_ENOENT) {
    ap_rputs( "chUserAgent: Kein Eintrag in APR!<br>\n", r );
}
*else* {
    ap_rprintf( r, "chUserAgent: %s<br>\n" , chUserAgent );
}

// I don't even get it using the getenv function:
char *chUserAgent2 = getenv("HTTP_USER_AGENT"); ap_rprintf( r, 
"chUserAgent2 using the getenv() function: %s<br>\n", chUserAgent2 );
8<--------8<--------8<--------8<--------8<--------8<--------8<--

I must have been missing something but I don't know what.

Many thanks for every reply,
    yours Henri





Re: no results with apr_env_get

Posted by Jeff Trawick <tr...@gmail.com>.
On Tue, 22 Mar 2005 13:08:04 +0100, Henri Schomäcker
<he...@virtual-homes.de> wrote:
> Hi folks,
> 
> I have a problem getting the environment variables with apr_env_get in 
> the request handler of my module.
> What I need are HTTP_USER_AGENT and REMOTE_ADDRESS but I just don't get 
> anything as a resullt in my char*.

The Apache "environment variables" are not available within the Apache
process via getenv.  Instead, do a lookup in the table
r->subprocess_env.

If you search through the Apache source code for the string
subprocess_env, you'll see numerous examples.  Here's one from
mod_unique_id:

apr_table_get(r->subprocess_env,
              "REDIRECT_UNIQUE_ID")