help files
Z505 | PasWiki | FUQ | Search | Main Docs | API Guide



Notes

Accessing special environment variables is made easy with the pwuenvvar unit.

In 1.6.1 the SERV constant was introduced which is slightly more elegant syntax than CgiEnvVar syntax in 1.6.0.X versions.

Examples

In 1.6.1 versions of powtils the syntax available is:
 program example;  {$mode delphi}
 uses
   pwuenvvar, pwumain;
 
 begin
   outln('<pre>');
   outln(  'Document root: '   + SERV.docroot);
   outln(  'Document name: '   + SERV.docname + ' (not avail on all servers)');
   outln(  'HTTP Accept: '     + SERV.accept);
   outln(  'Path info: '       + SERV.pathinfo);
   outln(  'Path translated: ' + SERV.pathtranslated);
   outln(  'Query string: '    + SERV.querystring);
   outln('</pre>');
   // and many more.. see pwuenvvar.pas
 end.
In 1.6.0.X it looks like (and 1.6.1 is backwards compatible with):
 program test;  {$mode delphi}
 uses
   pwuenvvar, pwumain;
 
 begin
   webwriteln('<pre>');
   webwriteln('Document root: ' + CgiEnvVar.DocRoot);
   webwriteln('Document name (not avail on all servers): ' + CgiEnvVar.DocName);
   webwriteln('HTTP Accept: ' + CgiEnvVar.Accept);
   webwriteln('Path info: ' + CgiEnvVar.PathInfo);
   webwriteln('Path translated: ' + CgiEnvVar.PathTranslated);
   webwriteln('Query string: ' + CgiEnvVar.QueryString);
   webwriteln('</pre>');
   // and many more! see pwuenvvar.pas
 end.

Tips

A good example of how to access all the special server variables is in the examples directory of your download, or on SVN.

You can still grab the special environment variables yourself manually:

 GetEnvVar('DOCUMENT_ROOT');
 GetEnvVar('SOME_OTHER');
This way, you can gain access to any server variable even if we haven't implemented wrappers for it using cleaner dot notation syntax yet.

Some servers do not support all the special variables. However most servers support common ones such as DOCUMENT_ROOT and SCRIPT_NAME.

If you use mode delphi, the syntax doesn't require extra () brackets:

   outln('Query string: ' + SERV.querystring);
Whereas if you use mode OBJFPC:
   outln('Query string: ' + SERV.querystring() );





lufdoc, Powtils, fpc, freepascal, delphi, kylix, c/c++, mysql, cgi web framework docs, Z505