| | |
|
|
|
Global context
The global context in Project Zero provides access to request, server and environment information much like the $GLOBALS, $_SERVER, $_REQUEST superglobals in PHP. Additionally, the global context can be used to share information between the various event handlers that can be built using Project Zero. The keys that are used to access content in the global context are called global context URI. This is discussed in detail in the Global context article in the Core Developer's Guide. These URIs and the data they represent play an important role in building Zero Applications. The URIs that can be used are listed in the Global context reference. The URIs are case-sensitive. It is possible for one script to set some data, for example in the request zone ('/request ...'), and have another script retrieve that value if it runs in the same request context.
In PHP, the global context is accessible through extension functions that typically take the global context URI as their arguments. The following functions are made available, by default, through the ZeroExtension declared in the default php.ini file:
Global context usage examples
The following table provides some global context usage examples.
| Action | PHP example |
| Get HTTP request URI | zget('/request/uri') |
Get value of User-Agent request header | zget('/request/headers/in/User-Agent') |
| Get list of request parameters | zlist('/request/params', false) |
Get value of request parameter parmName | $parms = zget('/request/params/parmName') |
| Set status | zput("/request/status",200) |
| Delete a key '/request/somekey' | zdelete('/request/somekey') |
| Add a header value no-cache to the Cache-Control header | zpost('/request/headers/out/Cache-Control', 'no-cache') |
| Get the username of a logged in user (secured pages only) | zget('/request/subject#remoteUser') |
| Get the list of groups for a logged in user (secured pages only) | zget('/request/subject#groups') |
| Get the list of roles for a logged in user (secured pages only) | zget('/request/subject#roles') |
|
|
r9 - 09 Dec 2007 - 14:56:39 - todkap
|
|
|
| | |