Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Unable to create session, add params, and redirect

by bradcathey (Prior)
on May 17, 2009 at 12:18 UTC ( [id://764503]=note: print w/replies, xml ) Need Help??


in reply to Re: Unable to create session, add params, and redirect
in thread Unable to create session, add params, and redirect

Thanks for your thinking on this. Appreciate it much. BTW, I'd never heard of URI, however, still not quite sure why you used it :)

The only thing I don't see in your code is where you add key/value param to the session. That's what is throwing me. I need to create the new session, add a param, and then redirect. It's too many headers.

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
  • Comment on Re^2: Unable to create session, add params, and redirect

Replies are listed 'Best First'.
Re^3: Unable to create session, add params, and redirect
by Anonymous Monk on May 17, 2009 at 13:53 UTC
    Too many headers? You know that you're supposed to print headers only once.
Re^3: Unable to create session, add params, and redirect
by Your Mother (Archbishop) on May 18, 2009 at 16:40 UTC

    Yeah, I'm sorry. I didn't read the original flow right. AM is right and I alluded to it above. You can't print headers twice or you'll get wonky behavior. Give something like this a spin.

    my $current_page = shift || die "Need a current page"; my $session = CGI::Session->new or die CGI::Session->errstr; my @pages = $session->param('authorized_pages'); push @pages, $current_page unless $pages[-1] eq $current_page; # Just a guess. $session->param( authorized_pages => \@pages ); $session->flush(); my $uri = URI->new( CGI::url() ); $uri->query("page=1"); $uri->fragment(""); print $session->header(-location => $uri, -status => 302 );

    URI is in there to get the absolute URI and mess with the query string and fragment. Munging URI as strings is like parsing HTML with regexes. It can be done but it's error prone and why shoot yourself in the foot when there are great tools that are just as easy, if not easier.

      You can't print headers twice or you'll get wonky behavior
      Everything after headers is content, no wonky :D

        Well, wonky connotes more than you ascribe it. As for content it depends on how the server is setup and what kind of headers were sent. A GET 302 shouldn't have a body, for example, so if a 302 is erroneously followed by a 200, or whatever, it would probably get eaten. Wonkily.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://764503]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2024-04-23 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found