manishrathi has asked for the wisdom of the Perl Monks concerning the following question:

I was going through "instantiator CGI" in teamsite environment (Its a content management system). When this CGI is invoked its passed the iw_owner, iw_workarea, iw_role parameters. These parameters are not specified by the web server environment. So can these parameters be custom defined in the server environment ? If not, then how will server handle these paarmeters ?
  • Comment on Can CGI have different environment variables than the default environment variables provided by the server ?

Replies are listed 'Best First'.
Re: Can CGI have different environment variables than the default environment variables provided by the server ?
by desemondo (Hermit) on Jan 15, 2010 at 02:39 UTC
    Can CGI have different environment variables than the default environment variables provided by the server?

    Yes and no. Depends on what you mean by different. As a whole, the lists of environment variables are different. Some variables are common to both, while others are unique.

    #!/usr/bin/perl -w use strict; use warnings; my $i = 1; for (sort keys %ENV){ print "$i $_\n"; $i++; }


    On my current system these environment varibles were specific to the command line:
    APPDATA HOMEDRIVE HOMEPATH LOGONSERVER PROMPT SESSIONNAME SWIFT_TRACE SYSTEMDRIVE SYSTEMROOT TEMP TMP USERDNSDOMAIN USERDOMAIN USERNAME USERPROFILE VS90COMNTOOLS WF_RESOURCES WINDIR

    And these were specific to the webserver:

    CONTENT_LENGTH GATEWAY_INTERFACE HTTPS HTTP_ACCEPT HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE HTTP_CONNECTION HTTP_HOST HTTP_USER_AGENT INSTANCE_ID LOCAL_ADDR PATH_INFO PATH_TRANSLATED REMOTE_ADDR REMOTE_HOST REQUEST_METHOD SCRIPT_NAME SERVER_NAME SERVER_PORT SERVER_PORT_SECURE SERVER_PROTOCOL SERVER_SOFTWARE

    And these are common to both:
    ALLIANCE ALLUSERSPROFILE ARCH COMMONPROGRAMFILES COMPUTERNAME COMSPEC CSYS_DCE_CLIENT_PROT CVSROOT DCE_CLIENT_PROT DCE_SERVER_PROT ERRLOG_CATALOG_DIR FP_NO_HOST_CHECK NUMBER_OF_PROCESSORS OAPI_TRACE OAPI_TRACE_INSTANT_FLUSH OS PATH PATHEXT PROCESSOR_ARCHITECTURE PROCESSOR_IDENTIFIER PROCESSOR_LEVEL PROCESSOR_REVISION PROGRAMFILES
Re: Can CGI have different environment variables than the default environment variables provided by the server ?
by ikegami (Patriarch) on Jan 15, 2010 at 03:05 UTC

    You say parameters. Do you mean environment variables?

    Processes get their environment from their parent. Usually, they get a copy of their parent's. If you set the variable for the web server, the CGI child will probably inherit it. It may also be possible to configure your web server to set custom environment variables for the CGI child.

    This question has nothing to do with Perl. Please consult your web server's documentation or those supporting your web browser.

    Update: What's stopping you from setting the env vars you need in the CGI script itself?

Re: Can CGI have different environment variables than the default environment variables provided by the server ?
by MidLifeXis (Monsignor) on Jan 15, 2010 at 15:23 UTC

    I do this using apache, via the SetEnv parameter. I use it for setting things that change based on the environment it is running in, for running two instances of an application under different roots, etc.

    --MidLifeXis