in reply to Re: Returning to A Referring Page
in thread Returning to A Referring Page

You will also need to incorporate a default value as you cannot always be sure that the HTTP_REFERER environment variable will be set. eg.

$jump_to = $ENV{'HTTP_REFERER'} || 'http://www.yourwebpage.com'; print "Location: $jump_to\n\n";

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Replies are listed 'Best First'.
Re: Re: Re: Returning to A Referring Page
by little (Curate) on Jan 20, 2002 at 16:15 UTC
    Just to make it complete though:
    $jump_to = $ENV{'HTTP_REFERER'} || 'http://www.yourwebpage.com'; print "Status: 302 Moved\n"; # thats the spec print "Location: $jump_to\n\n";
    Some Browsers would ignore the redirection attempt without the correct status. But if you use CGI.pm it will do it for you :-)

    Have a nice day
    All decision is left to your taste
      I don't know about other webservers, but Apache changes the status according to the other headers. If there's a Location: header, the status will be 302.
      Status headers aren't sent as-is to the browser, they're in the first response line: HTTP/1.1 302 Moved.

      2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$