On Tue, 30 Nov 1999, Ofer Inbar wrote:

> Michael Dearman <[EMAIL PROTECTED]> wrote:
> > I've come close to figuring this one out buy following some of the
> > questions I've seen here. But...
> > 
> > <H1>Hello $ENV{REMOTE_HOST}</H1>
> > 
> > The remote host doesn't show. Printing out the %ENV, it tain't there.
> > But where does Perl get it. From CGI.pm (which is installed) or where?
> 
> %ENV is the environment.  CGI uses the environment to pass values from
> the web server to the CGI program.  If your script was running under
> CGI, the web server would put REMOTE_HOST, and other things, in the
> environment, before forking to run your script.  But you're not using
> CGI, you're using mod_perl.  

> The server isn't setting CGI environment variables 

This is not quite true. The server does sets the %ENV to emulate mod_cgi
in order to server modules like CGI.pm that expects these variables to be
available for their convenience. This setting adds an overhead, which you
might consider to reduce. For more info read:
http://perl.apache.org/guide/performance.html#PerlSetupEnv_Off

This is an easy prove that %ENV is set (while not all variables are
present as with mod_cgi, particularly REMOTE_HOST isn't there...)

PerlModule MyEnv
<Location /env>
  SetHandler perl-script
  PerlHandler MyEnv
</Location>

package MyEnv;
use Apache;
use Apache::Constants;
sub handler{ 
  my $r = shift; 
  print $r->send_http_header("text/plain"); 
  print map {"$_ => $ENV{$_}\n"} keys %ENV;
  return OK;
}
1;

http://localhost/env prints:

SERVER_SOFTWARE => Apache/1.3.10-dev (Unix) mod_perl/1.21_01-dev
DOCUMENT_ROOT => /home/httpd/docs
GATEWAY_INTERFACE => CGI-Perl/1.1
REMOTE_ADDR => 127.0.0.1
SERVER_PROTOCOL => HTTP/1.0
SERVER_SIGNATURE => <ADDRESS>Apache/1.3.10-dev Server at
inx006.iil.intel.com Port 80</ADDRESS>

REQUEST_METHOD => GET
QUERY_STRING => 
HTTP_USER_AGENT => Mozilla/4.7 [en] (X11; I; Linux 2.2.12-20 i686)
PATH => /bin:/usr/bin
HTTP_CONNECTION => Keep-Alive
HTTP_ACCEPT => image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
image/png, */*
REMOTE_PORT => 3167
SERVER_ADDR => 127.0.0.1
HTTP_ACCEPT_LANGUAGE => en
MOD_PERL => mod_perl/1.21_01-dev
SCRIPT_NAME => /env
SCRIPT_FILENAME => /home/httpd/docs/env
HTTP_ACCEPT_ENCODING => gzip
SERVER_NAME => inx006.iil.intel.com
REQUEST_URI => /env
HTTP_ACCEPT_CHARSET => iso-8859-1,*,utf-8
SERVER_PORT => 80
HTTP_HOST => localhost
SERVER_ADMIN => [EMAIL PROTECTED]

> and forking to run your script.  Your script is being run by
> a code module that is part of the web server.  You need to use Apache
> specific calls to get the information you need from the web server.
> mod_perl makes this easy to do using the "Apache request object":
> 
>  $request = Apache->request;
>  $connection = $request->connection;
>  $remote_ip = $connection->remote_ip;
> 
> Read more about the request object in the mod_perl documentation, to
> find out how to ask it for the other kinds of information a CGI script
> normally gets out of the environment.  Remember, mod_perl is not CGI
> (although with Apache::Registry it can look quite similar to CGI)
> 
>   --  Cos (Ofer Inbar)  --  [EMAIL PROTECTED]  [EMAIL PROTECTED]
>   --  Exodus Professional Services  --  [EMAIL PROTECTED]
>  "This may seem a bit weird, but that's okay, because it is weird."
>     -- Larry Wall in perlref(1) man page, Perl 5.001
> 
> 



_______________________________________________________________________
Stas Bekman  mailto:[EMAIL PROTECTED]    www.singlesheaven.com/stas  
Perl,CGI,Apache,Linux,Web,Java,PC at  www.singlesheaven.com/stas/TULARC
www.apache.org  & www.perl.com  == www.modperl.com  ||  perl.apache.org
single o-> + single o-+ = singlesheaven    http://www.singlesheaven.com

Reply via email to