setting cookie then redirect problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bagsmode

    setting cookie then redirect problem

    Hi,

    I'm trying to set a session cookie and then redirect, however I get the
    error:

    Status: 302 Moved Location: /index.cgi

    I thought I recall getting an error like this when I first tried
    performing a redirect when I had left in
    print "Content-type:text/html\n\n";
    before the redirect. After removing that print statement, I was able to
    get the redirect test script to execute correctly.

    Now I'm getting this "Moved Location" message again. While I'm not doing
    the print of the Context.. I am doing a print when saving (?) the cookie
    info with:
    print $cgi->header( -cookie=>$cookie );

    BTW, I tried using #$CGI::Session->header($cgi) ; but I get an error when
    trying to use this about header not being defined or some-such.

    TIA
    Glenn

    Below is the full script:
    VVVVVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVVVV
    #!c:/Perl/bin/Perl.exe

    use CGI;
    use CGI::Session;
    use CGI::Carp qw(fatalsToBrow ser);

    # READ IN VALUES

    read(STDIN, $buffer, $ENV{'CONTENT_L ENGTH'});
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
    }


    # SET "login" AND "pswd"
    $session = new CGI::Session("d river:File", undef,
    {Directory=>"/windows/temp"});
    foreach $key (sort (keys(%FORM))) {
    if ($FORM{$key} eq "") {
    die_nice("Pleas e fill out the field for <b>$key</b>.");
    }
    $session->param($key, $FORM{$key});
    }

    $cgi = new CGI;
    $cookie = $cgi->cookie(CGISESS ID => $session->id);
    print $cgi->header( -cookie=>$cookie );

    # REDIRECT BACK TO INDEX
    my $url = '/index.cgi';
    print $cgi->redirect($url) ;

    exit;

    sub die_nice {
    print "Content-type:text/html\n\n";
    print "<html><head><t itle>Login Failed</title></head><body>";
    my ($err_msg) = @_;
    print "<h2><b>Err or</b></h2><p>";
    print "$err_msg<p >";
    print "<br>Use the BACK button to return to the form with your
    current fields filled in\n";
    print "</body></html>";
    exit;
    }
    ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

  • Jeff Bars

    #2
    Re: setting cookie then redirect problem

    Something like this may help...

    reDir("http://wwww.somewhere. com/disclaimer.html ");

    sub reDir{
    $IIS = ($ENV{'SERVER_S OFTWARE'} && ($ENV{'SERVER_S OFTWARE'} =~ /iis/i)) ?
    1:0;
    chdir($1) if (($IIS) && ($0 =~ /(.*)(\\|\/)/));
    print "HTTP/1.0 302 Temporary Redirection\r\n " if ($IIS);
    print "Content-type: text/html\r\n";
    print "Location: $_[0] \r\n\r\n";
    }

    -JB





    "bagsmode" <bagsmode@front iernet.net> wrote in message
    news:3F2313F8.6 040501@frontier net.net...[color=blue]
    > Hi,
    >
    > I'm trying to set a session cookie and then redirect, however I get the
    > error:
    >
    > Status: 302 Moved Location: /index.cgi
    >
    > I thought I recall getting an error like this when I first tried
    > performing a redirect when I had left in
    > print "Content-type:text/html\n\n";
    > before the redirect. After removing that print statement, I was able to
    > get the redirect test script to execute correctly.
    >
    > Now I'm getting this "Moved Location" message again. While I'm not doing
    > the print of the Context.. I am doing a print when saving (?) the cookie
    > info with:
    > print $cgi->header( -cookie=>$cookie );
    >
    > BTW, I tried using #$CGI::Session->header($cgi) ; but I get an error when
    > trying to use this about header not being defined or some-such.
    >
    > TIA
    > Glenn
    >
    > Below is the full script:
    > VVVVVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVVVV
    > #!c:/Perl/bin/Perl.exe
    >
    > use CGI;
    > use CGI::Session;
    > use CGI::Carp qw(fatalsToBrow ser);
    >
    > # READ IN VALUES
    >
    > read(STDIN, $buffer, $ENV{'CONTENT_L ENGTH'});
    > @pairs = split(/&/, $buffer);
    > foreach $pair (@pairs) {
    > ($name, $value) = split(/=/, $pair);
    > $value =~ tr/+/ /;
    > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    > $FORM{$name} = $value;
    > }
    >
    >
    > # SET "login" AND "pswd"
    > $session = new CGI::Session("d river:File", undef,
    > {Directory=>"/windows/temp"});
    > foreach $key (sort (keys(%FORM))) {
    > if ($FORM{$key} eq "") {
    > die_nice("Pleas e fill out the field for <b>$key</b>.");
    > }
    > $session->param($key, $FORM{$key});
    > }
    >
    > $cgi = new CGI;
    > $cookie = $cgi->cookie(CGISESS ID => $session->id);
    > print $cgi->header( -cookie=>$cookie );
    >
    > # REDIRECT BACK TO INDEX
    > my $url = '/index.cgi';
    > print $cgi->redirect($url) ;
    >
    > exit;
    >
    > sub die_nice {
    > print "Content-type:text/html\n\n";
    > print "<html><head><t itle>Login Failed</title></head><body>";
    > my ($err_msg) = @_;
    > print "<h2><b>Err or</b></h2><p>";
    > print "$err_msg<p >";
    > print "<br>Use the BACK button to return to the form with your
    > current fields filled in\n";
    > print "</body></html>";
    > exit;
    > }
    > ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
    >[/color]


    ---
    Posted via news://freenews.netfront.net
    Complaints to news@netfront.n et

    Comment

    • bagsmode

      #3
      Re: setting cookie--retrieval issue (was Re: setting cookie thenredirect problem)

      Jeff Bars wrote:[color=blue]
      > Something like this may help...
      >
      > reDir("http://wwww.somewhere. com/disclaimer.html ");
      >
      > sub reDir{
      > $IIS = ($ENV{'SERVER_S OFTWARE'} && ($ENV{'SERVER_S OFTWARE'} =~ /iis/i)) ?
      > 1:0;
      > chdir($1) if (($IIS) && ($0 =~ /(.*)(\\|\/)/));
      > print "HTTP/1.0 302 Temporary Redirection\r\n " if ($IIS);
      > print "Content-type: text/html\r\n";
      > print "Location: $_[0] \r\n\r\n";
      > }
      >
      > -JB
      >
      > "bagsmode" <bagsmode@front iernet.net> wrote in message
      > news:3F2313F8.6 040501@frontier net.net...
      >[color=green]
      >>Hi,
      >>
      >>I'm trying to set a session cookie and then redirect, however I get the
      >>error:
      >>
      >>Status: 302 Moved Location: /index.cgi
      >>
      >>I thought I recall getting an error like this when I first tried
      >>performing a redirect when I had left in
      >> print "Content-type:text/html\n\n";
      >>before the redirect. After removing that print statement, I was able to
      >>get the redirect test script to execute correctly.
      >>
      >>Now I'm getting this "Moved Location" message again. While I'm not doing
      >>the print of the Context.. I am doing a print when saving (?) the cookie
      >>info with:
      >> print $cgi->header( -cookie=>$cookie );
      >>
      >>BTW, I tried using #$CGI::Session->header($cgi) ; but I get an error when
      >>trying to use this about header not being defined or some-such.
      >>
      >>TIA
      >>Glenn
      >>
      >>Below is the full script:
      >>VVVVVVVVVVVVV VVVVVVVVVVVVVVV VVVVVVVVVVVVVVV V
      >>#!c:/Perl/bin/Perl.exe
      >>
      >>use CGI;
      >>use CGI::Session;
      >>use CGI::Carp qw(fatalsToBrow ser);
      >>
      >># READ IN VALUES
      >>
      >>read(STDIN, $buffer, $ENV{'CONTENT_L ENGTH'});
      >>@pairs = split(/&/, $buffer);
      >>foreach $pair (@pairs) {
      >> ($name, $value) = split(/=/, $pair);
      >> $value =~ tr/+/ /;
      >> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      >> $FORM{$name} = $value;
      >>}
      >>
      >>
      >># SET "login" AND "pswd"
      >>$session = new CGI::Session("d river:File", undef,
      >>{Directory= >"/windows/temp"});
      >>foreach $key (sort (keys(%FORM))) {
      >> if ($FORM{$key} eq "") {
      >> die_nice("Pleas e fill out the field for <b>$key</b>.");
      >> }
      >> $session->param($key, $FORM{$key});
      >>}
      >>
      >>$cgi = new CGI;
      >>$cookie = $cgi->cookie(CGISESS ID => $session->id);
      >>print $cgi->header( -cookie=>$cookie );
      >>
      >># REDIRECT BACK TO INDEX
      >>my $url = '/index.cgi';
      >>print $cgi->redirect($url) ;
      >>
      >>exit;
      >>
      >>sub die_nice {
      >> print "Content-type:text/html\n\n";
      >> print "<html><head><t itle>Login Failed</title></head><body>";
      >> my ($err_msg) = @_;
      >> print "<h2><b>Err or</b></h2><p>";
      >> print "$err_msg<p >";
      >> print "<br>Use the BACK button to return to the form with your
      >>current fields filled in\n";
      >> print "</body></html>";
      >> exit;
      >>}
      >>^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^[/color][/color]

      BTW, first off, let me thank Jeff for helping me with the redirect :)
      Ended up needing to do meta refresh to forward to the next page.

      Now, I'm having an issue with getting the information FROM the cookie.
      After saving the login info in the script above using:
      $session->param($key, $FORM{$key});
      (I'm getting the login information via POST form).

      Then I try to retry the information using the method shown at CPAN under
      CGI::Session::T utorial :
      --- script redirected to after saving cookie info above ---
      #!c:/Perl/bin/Perl.exe

      use DBI;
      use CGI;
      use CGI::Session;
      use CGI::Carp qw(fatalsToBrow ser);

      # CHECK FOR COOKIE INFO--IF DOESN'T EXIST, SEND TO LOGIN
      $cgi = new CGI;
      $sid = $cgi->cookie('CGISES SID') || $cgi->param('CGISESS ID') || undef;
      $session = new CGI::Session(un def, $sid, {Directory=>'/windows/temp'});
      my $login_name = $session->param(-name=>'login');
      --- end ---

      When this executes, I get the following:
      Software error:

      flock() unimplemented on this platform at
      C:/Perl/lib/CGI/Session/File.pm line 54.

      Should I be using a different version since I'm on win98 of either
      CGI::Session or CGI::Session::F ile?

      Thanks,
      Glenn

      Comment

      Working...