Injecting server variables in a PHP script from an Apache module

January 21st, 2010 by Jérôme Leave a reply »

In case it help someone, here is a function that makes it possible to inject server variables in a PHP script so it is available in the $_SERVER array.

The function looks like this :

static void inject_server_variable(request_rec *r, const char *name, const char *value)
{
    apr_table_set(r->notes, name, value);
    apr_table_set(r->subprocess_env, name, value);
}

The line :

apr_table_set(r->notes, name, value);

makes it possible to fetch the variable by using the apache_note function.

The line :

apr_table_set(r->subprocess_env, name, value);

stores the variable in the $_SERVER array so it can be fetched only by doing a simple print($_SERVER['xxxx'])

:)

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Advertisement

Comments are closed.