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

Hi

I can't work out why I cannot get the value of $ENV{REDIRECT_URL} through this code:
#!/usr/bin/perl -w use CGI; my $q = new CGI; my $rcode=$ENV{REDIRECT_STATUS}; my $bstatus=($sendrealresponse)?"$rcode $messages{$rcode}":"200 Interc +epted error condition"; my $time=gmtime(time); my %swapdata=(url=>$ENV{REDIRECT_URL},notes=>$ENV{REDIRECT_ERROR_NOTES +}, code=>$rcode,message=>$messages{$rcode}, requester=>$ENV{REMOTE_AD +DR}, reqhost=>$ENV{REMOTE_HOST}, server=>$ENV{HTTP_HOST}, referrer=>$ +ENV{HTTP_REFERER}, time=>$time);
when I try to pass the value of url on (ie $swapdata{url}), it is always empty

Replies are listed 'Best First'.
Re: can't get value of $ENV{REDIRECT_URL}
by rinceWind (Monsignor) on Dec 02, 2003 at 17:41 UTC
    You need to give a bit more information. What webserver are you running on which operating system?

    When you answer that, you will usually find that the documentation for the webserver will tell you precisely which environment variables it passes into any scripts. It's also useful to have an "envdump.pl" script in your cgi-bin directory.

    #!/usr/bin/perl -w use strict; use CGI qw(:standard); use Data::Dumper; print header, start_html('Environment vars'); print pre(Dumper(\%ENV)), end_html;
    Hope this helps.

    --
    I'm Not Just Another Perl Hacker
      thanks - I ran the dumper script and thesea re the values I get:
      $VAR1 = { 'QUERY_STRING' => '', 'HTTP_X_FORWARDED_FOR' => '81.78.90.129', 'SERVER_ADDR' => '212.67.202.134', 'HTTP_ACCEPT_LANGUAGE' => 'en-gb', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'HTTP_CONNECTION' => 'keep-alive', 'HTTP_ACCEPT' => 'image/gif, image/x-xbitmap, image/jpeg, im +age/pjpeg, */*', 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 6.0; Win +dows NT 5.1; Alexa Toolbar)', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'HTTP_HOST' => 'www.photographersdirect.com', 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) (Red-Hat/Linux) +Chili!Soft-ASP/3.6.2 mod_ssl/2.8.14 OpenSSL/0.9.6b PHP/4.1.2 FrontPag +e/5.0.2.2510', 'SERVER_ADMIN' => 'webmaster@photographersdirect.com', 'REMOTE_ADDR' => '195.92.67.69', 'SCRIPT_NAME' => '/formmail/dumper.cgi', 'SERVER_NAME' => 'photographersdirect.com', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'DOCUMENT_ROOT' => '/home/picturesea/public_html', 'REQUEST_URI' => '/formmail/dumper.cgi', 'HTTP_VIA' => '1.1 webcacheH05 (NetCache NetApp/5.3.1R2)', 'REQUEST_METHOD' => 'GET', 'SCRIPT_FILENAME' => '/home/picturesea/public_html/formmail/ +dumper.cgi', 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'SERVER_PORT' => '80' };
      I can't see anything here that shows the file it redirected from.

      Edit: BazB changed pre tags to code tags.

        $ENV{HTTP_REFERER} is used for that purpose, IIRC. Don't rely on it too much though, since it can be faked, or left out completely.

        Update: To be honest, I have never heard of anything like $ENV{REDIRECT...} variables with Apache :(

        --
        B10m
Re: can't get value of $ENV{REDIRECT_URL}
by simonm (Vicar) on Dec 02, 2003 at 18:29 UTC
    As described in the Apache docs, this variable is only set in a few special cases, eg. error handling. Are you sure that the request you're making is such that it would have these available?