This script gives the user a selection which is more secure than a text box. If the URL shown is what you want then remove the hash from #Search and it should redirect.
#!/usr/bin/perl # n.cgi use strict; use CGI qw( :standard ); use CGI::Carp qw( fatalsToBrowser ); use Date::Calc qw(Add_Delta_Days); # calc dates my ($d,$m,$y) = (localtime)[3,4,5]; $y+=1900; $m+=1; my ($y0,$m0,$d0) = Add_Delta_Days($y,$m,$d,-7); my $FM = sprintf "%02d-%02d-%04d",$m0,$d0,$y0; my $TM = sprintf "%02d-%02d-%04d",$m,$d,$y; # page layout my $page =<< "EndOfText"; <h2>Add Logical:</h2> <form name="form" method="post" action="n.cgi"> <table> <tr> <td align="right"><strong>Logical:</strong></td> <td> <select name="server"> <option value="">select</option> <option value="server1">server1</option> <option value="server2">server2</option> <option value="server3">server3</option> <option value="server4">server4</option> </select> </td> </tr> <tr> <td colspan="2"> &nbsp; </td> </tr> <tr> <td> &nbsp; </td> <td> <input type="submit" name="action" value="Search" /> </td> </tr> </table> </form> EndOfText # get parameters my $q = CGI->new; my $action = $q->param('action'); my $server = $q->param('server'); # construct URL my $URL = join ";","http://a.com:8080/bms/healthMonitor.do?method=redi +rect", "operation=BackupHistorySearch", "subOperation=GetReport", "clientName=$server", "fromDateStr=$FM", "toDateStr=$TM"; # redirect if required if ($action eq '#Search'){ # remove hash to redirect print $q->redirect($URL); } else { print $q->header, $q->start_html('Page Title'), $page, # hash out next 2 lines or remove if OK $q->p("Vars action=$action : server=$server : FM=$FM : TM=$TM "), $q->a({-href=>$URL, -target=>'_blank'},$URL), $q->end_html; }
poj

In reply to Re: Perl CGI redirect by poj
in thread Perl CGI redirect by aksusa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.