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

Alright. I'm new to perl and cgi. but, what i'm trying to do is make a script that will add something to one of my log files (i got that part working) then redirect to a file to download on another server. print "Location: blah" gives me a 302 moved, and has the link pointing to the cgi itself, not the url i wanted...please..somone share your wisdom with me. this is driveing me nuts

Replies are listed 'Best First'.
Re: Trying to redirect...
by LD2 (Curate) on Mar 17, 2001 at 14:17 UTC
    You may want to look at this node: CGI and redirect.. I believe it will most likely answer your question. If not, please be more specific (i.e. post your code?).

      Yeah, i tried that alredy..

      here's the code where the problem is (assume all varibles exist, i have checked they do.)
      if ($query->param('loc') eq '2') { print $query->redirect("$productDL2") }else{ print $query->redirect("$productDL1") }

      Also, i dont print anything before this, and i seem to be getting redirected back to the cgi (when i access it, IE pops up a little "the attempt to load 'accessing URL: http://mycgi'slocation' failed" error

      2001-03-17 Edit by Corion: Added formatting and <CODE> tags

        I don't think you quite read that last node..you may want to try what jjhorner suggested. I believe that comatose explains it, "Redirect is for telling a browser that the site it was looking for has moved. Location is for redirects as most people think of them.".. you need to use location and not redirect.
Re: Trying to redirect...
by axidpk (Initiate) on Mar 17, 2001 at 17:39 UTC
    for the location thing to work u have to print out Location: http://www.blahblah.com here's a simple script to redirect a visitor to pakipunch.com
    #!/usr/bin/perl print "Location: http://www.pakipunch.com\n\n"; exit 14;
    -- or ---
    #!/usr/bin/perl $href="http://www.pakipunch.com"; print "Location: $href\n\n"; exit 14;
    ------------
    Ahmad Mushtaq
    ahmadpak@hotmail.com
    http://coolperl.da.ru
      using exit() at random places might screw up mod_perl a bit. Since perl will exit anyway, I see no use for it in this particular case.

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
Re: Trying to redirect...
by skazat (Chaplain) on Mar 18, 2001 at 12:21 UTC

    I just had this same problem working on an NT box, I was using the

    print "Location: http://blah.com\n\n";

    and getting a '302' error. I then switch to using the CGI.pm method, redirect:

    use CGI qw(:standard); my $query = CGI -> new(); $query -> redirect(-uri => 'http://blah.com');

    But got the same error, I then added the 'nph' (no parse header) to the rediect() call:

    use CGI qw(:standard); my $query = CGI -> new(); $query -> redirect(-u +ri => 'http://blah.com', nph => 1);

    and everything worked dandy. I was also passing a cookie in the redirect, so that may have had something to do with it. Like I said, this was on an NT IIS server.

     

    -justin simoni
    !skazat!