问题
For my form validation page, I'd like to create a cookie and be redirected to another page but that doesn't work. Redirection prevents the creation of cookie. Do you have any solution ?
回答1:
One way of doing it is on the landing page add a flag (Query Parameter) in there to tell it to create cookie.
http://domain/page?create_cookie=true
if create_cookie exist the landing page will create the cookie.
回答2:
A way to proceed is to create the cookie from a G-WAN handler, bypassing the servlet or the automatically generated redirection, but you can also use this method:
#include "gwan.h" // G-WAN exported functions
int main(int argc, char *argv[])
{
char redir[] = "Cookie: blah\r\n" // add a cookie in the response
"Location: 100.html\r\n\r\n";
http_header(HEAD_ADD, redir, sizeof(redir) - 1, argv);
return 301; // return an HTTP code (301:'Moved')
}
来源:https://stackoverflow.com/questions/14886351/gwan-redirection-after-create-cookie