Retrieving Environment and Script Information

This section provides a tutorial example on how to retrieve information about the Web server environment and about the current CGI script file.

The next group of methods we want to test is for retrieving information from the Web server about the environment and the script file itself. Here is a simple example Perl CGI script:

#- Copyright (c) 2014,, All Rights Reserved.
   use CGI;
   $query = CGI->new();

   $text = "";
   $text .= "Request method = ".$query->request_method()."\n";
   $text .= "Request URI = ".$query->url(-query=>1)."\n";

   $text .= "Path info = ".$query->path_info()."\n";
   $text .= "Path translated = ".$query->path_translated()."\n";
   $text .= "Remote host = ".$query->remote_host()."\n";
   $text .= "Remote addr = ".$query->remote_addr()."\n";
   $text .= "Script name = ".$query->script_name()."\n";
   $text .= "Referer = ".$query->referer()."\n";
   $text .= "Server name = ".$query->server_name()."\n";
   $text .= "Server port = ".$query->server_port()."\n";
   $text .= "Server software = ".$query->server_software()."\n";
   $text .= "Remote user = ".$query->remote_user()."\n";
   print $query->header();
   print $query->start_html(-title=>'');
   print $query->pre($text);
   print $query->end_html();

Copy to C:\local\apache\htdocs and browse to: http://localhost/

You should see the following result in the browser.

Request method = GET
Request URI = 
Path info = 
Path translated = 
Remote host =
Remote addr =
Script name = /
Referer = 
Server name = localhost
Server port = 80
Server software = Apache/2.2.25 (Win32)
Remote user = 

Two interesting notes:

Last update: 2014.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Converting Perl Script to Executable Binary

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server Module for Building Web Pages

 What Is

 Generating HTML Document with

 Retrieving Query Parameters and Headers

Retrieving Environment and Script Information

 Redirecting Browser to a URI

 "Refresh" http-equiv Meta Tag

 What Is CGI::Cookie?

 Retrieving and Setting HTTP Cookies

 LWP::UserAgent and Web Site Testing


 PDF Printing Version