PTM Logo Version 0.5.1 Beta
Home    SVN    Downloads    Documentation    Forum    Contact
This Site is 100%
Powered by PTM Logo
I   Index
III   Description
IV   Installation
V   Language Overview
VI   Tags
VII   Variables
VIII   Functions
IX   Modules
View / Download this file.


    The implementation of PTM's %_SERVER variable is entirely dependent on the
    circumstances under which your PTM script is being run. %_SERVER is actually
    just a PTM port of Perl's %ENV variable, with a 'REQUEST_TIME' value added.
    So, depending on how your PTM script is being accessed (via the web or
    command line) %_SERVER will store a seperate set of values. However, since
    'REQUEST_TIME' is added by PTM at run-time, it will always be included.
    Because PTM was originally designed for web use with Apache, those values
    will be used for usage examples here. In the case of a web-access PTM script
    evaluation, %_SERVER stores information like HTTP host, server port,
    server protocol, server software, redirect status, document root, etc. Visit to get a list of environment variables it creates, or use the PTM
    Test file that comes with every PTM installation package to see a full list
    of %_SERVER values.

    %_SERVER is structured similar to the following:

      %_SERVER = (
        REQUEST_TIME    => time(),
        REQUEST_METHOD  => 'GET',
        SERVER_PORT     => '80',

    The %_SERVER keys (environment variable names) can be accessed as a list
    (array) with Perl's "keys" command like so:

      @var_names = keys %_SERVER;

    The environment variable values can be accessed by referencing the specific
    name of the requested variable:

      $var_value = $_SERVER{'REQUEST_TIME'};

    Notice that, when referencing a specific variable value, the '%' is changed
    to a '$' when referencing the hash, as you are referencing a specific value
    and not the entire hash.


    Example 1: Showing the Value of a Server Variable using the DISPLAY Tag

      The value of REQUEST_TIME is <?= $_SERVER{'REQUEST_TIME'} ?>.

    Example 2: Showing All the Vars using the DO and DISPLAY Tags and a Loop

      <? foreach $var (keys %_SERVER) { ?>
        The value of <?= $var ?> is <?= $_SERVER{$var} ?>.<br>
      <? } ?>





Home    SVN    Downloads    Documentation    Forum    Contact