[mod_python] setting apache variables from mod_python

Graham Dumpleton grahamd at dscpl.com.au
Thu Feb 16 18:03:29 EST 2006

matthew.garman at gmail.com wrote ..
> I'm looking to use mod_python to set some apache variables that can
> be read from PHP's $_SERVER variable.  I'm not sure how to do this
> in mod_python (I'm sure it's documented, but I don't know what to
> look for); I also don't know how to invoke such a beast from within
> a PHP script.

I am not sure by what mechanism you may be able to access them
from PHP, but suggest two options.

1. Set values in the req.notes table object.

2. Set values in req.subprocess_env table object.

The place to do them from in mod_python would be to specifying
a fixup handler (not a content handler) and do it there. A content
handler shouldn't be defined as that tends to disable execution of
PHP stuff. Thus:

  PythonFixupHandler setphpstuff

  # setphpstuff.py

  from mod_python import apache

  def fixuphandler(req):
    req.notes["STUFF_FOR_PHP"] = "value"
    req.subprocess_env["OTHER_STUFF_FOR_PHP"] = "value"
    return apache.OK


More information about the Mod_python mailing list