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

Have searched already and found replies! Most dating back to 2002 and some to 2001! I'm NOT on IIS, and everything works fine all except the 'redirect' part!!! Basically this code comes from an IFRAME where I'm calling &authenticate sub. If a user times-out if working within the IFRAME, I would like to redirect the '_top' frame to the login.cgi script. Here's my code:
my $query = new CGI; my $USER_COOKIE = $query->cookie('LOGGEDIN'); ##### COOKIEDATA FORMAT ##### sid : time : user : user_lang : user_perm my ( $CSID, $CTIMEIN, $USER, $USER_NAME, $USER_LANG, $USER_PERM, ) + = split (/\:/, $USER_COOKIE ); ##### DO TIMEOUT STUFF my $now = time(); if((( $now - $CTIMEIN ) < $timeout ) && ($CSID eq "$FORM{'sid'}")) + { ##### COOKIEDATA FORMAT ##### sid : time : user : user_name : user_lang : user_perm my $cookie_data = qq¿$CSID:$now:$USER:$USER_NAME:$USER_LANG:$U +SER_PERM¿; $expires = $now + $timeout ; ##### Set cookie : No need to redirect as session still valid my $user_loggedin = new CGI::Cookie( -name=>'LOGGEDIN', -value=>$cookie_data, -expires=>$expires, ); print "Set-Cookie: $user_loggedin\n"; } else{ ##### Redirect user to login.cgi my $user_loggedin = new CGI::Cookie( -name=>'LOGGEDIN', -value=>'', -expires=>'-1d', ); my $redirect = qq¿$SITE_BASE_URL/login.cgi?timeout=y¿; print $query->redirect( -cookie=>$user_loggedin, -uri=>$redirect, -target=>'_top', ); exit(0); }
From what I've read both here and http://search.cpan.org/~lds/CGI.pm-3.08/CGI.pm the $query->redirect does not support the -target=> arg and those that do support -target=> arg, I can't really work out how to use them with what I've already got. Can anyone help? Any takers? Many thianks as usual to those who take the time to reply ;-)

Replies are listed 'Best First'.
Re: Set Cookie & Redirect from IFRAME
by eibwen (Friar) on Apr 21, 2005 at 01:59 UTC
    Can you clarify the apparent contradiction:
    $query->redirect does not support the -target=>arg and those that do support -target=>arg

    UPDATE: It occurs to me that you may have omitted puncuation, and therefore meant that you found some examples using -target as an argument to the redirect method, but you don't know how to adapt the code. Nevertheless, please post all relevant example code pertaining to the use of -target as a redirect argument.

Re: Set Cookie & Redirect from IFRAME
by PodMaster (Abbot) on Apr 21, 2005 at 08:02 UTC
    If you read the HTTP RFC (and you should), it doesn't mention any Window-target header because it's not part of HTTP.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Set Cookie & Redirect from IFRAME
by dorward (Curate) on Apr 21, 2005 at 09:04 UTC

    HTTP provides no mechanism for mucking about with frames. The only way to do this would be to redirect to a document that would be loaded into the iframe and from there use client side technology to change the frames.

    Something along the lines of some JavaScript:

    window.onload = function() { top.location = '/'; }

    With a fallback to a regular link:

    <p>Your session has timed out. Please <a href="/" target="_top">log in again</a>.</p>

    Should do the trick. Or you could avoid using frames in the first place.