I don't know anyone who has used CGI since 1998 or so, but I haven't done any web programming in a long time so I guess it's still kicking around.

I've done a basic cleanup (adding use strict; and use warnings; (use those pragmas in all of your Perl programs), fixing all errors and ensuring all vars are set so there aren't any warnings when running the script on the command line. I've also made a few other slight changes, such as basic layout, and appending a semi-colon to the lines that are run in the if() statements.

I'd recommend trying to fix the errors use strict; complains about yourself, using my post as a reference if needed.

#!/usr/bin/perl use strict; use warnings; # # PROGRAM: resumepath.pl # # PURPOSE: This script checks the request for cookies and environ +ment variables and redirects customer # back to the federation environment with good session # CREATED: June 30, 2015 by Mitchell Lewars # Thanks for help to Bj&#65533;rn Vildljung # Lots of examples used from Perl Monks web site use CGI qw(:standard); my $query = new CGI; my $perror = 0; #//Set to 1 in case of an error. my $wearelooping = 0; #//Set to one if a user returns withing 15 se +conds, indicating a redirect-loop. my $redirectURL = "https://federate-qa.localhost.com"; #---- Next get the current values my $gotcookies = $ENV{"HTTP_COOKIE"}; my $env = $query->param('env'); my $resumepath = $query->param('resumePath'); #// Check for the env= entry in the URL. If it is set to prod, use pro +d federation, else use QA. if ( $env and $env eq 'prod'){ $redirectURL = "https://federate.localhost.com"; } #// Check that the PF-session information is passed as expected, if no +t, we got an error. Otherwise, add it to redirectURL if ( $resumepath ){ $redirectURL .= $resumepath; } else { $perror=1; } # Verify that there is an SMSESSION, otherwise we got somebody accessi +ng us the wrong way, and therefor probably for the wrong reasons. ERR +OR! if (!( $gotcookies =~ /smsession/i)){ $perror = 1; } # Check if there is already an SMPF, if so we are looping if ( $gotcookies =~ /smpf/i){ $wearelooping = 1; } #// Check to see if a Cookie named SMPF is avalible. If not, we set it + and give it a 15 second lifetime. If it is there, we got a redirect +loop. my $cookie; if ($wearelooping eq 0 and $perror eq 0){ $cookie = $query->cookie(-name=>'SMPF', -value=>'1', -expires=>'+15s', -path=>'/'); print $query->redirect( -cookie => $cookie, -uri => "$redirectURL"); print $query->start_html( -title=>'Login'); print $query->end_html; } else { $cookie = $query->cookie(-name=>'SMPF', -value=>'', -expires=>'now', -path=>'/'); print $query->header(-cookie=>$cookie); print $query->meta(''); print $query->start_html('Login'); print $query->body("<big><big><b>Redirect loop!</b></big></big><b +r><br> You have been assigned a SESSION-cookie, as confirmation that +you have successfully logged in. For some reason the login-servers wh +o needs this cookie is not getting it from your browser, causing a lo +op of redirection. Please try to go back to the site you want to logi +n to and try again. <b>You should not need to enter your credentials +again</b>. If this error is reoccurring for you, try using a differen +t browser."); print $query->end_html; }

-stevieb


In reply to Re: CGI to redirect using sessions by stevieb
in thread CGI to redirect using sessions by lewars

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.