set cookie and redirect
set cookie and redirect
(OP)
can a script print cookies to the header and redirect?
i have an shtml page calling a perl cgi script through ssi.
the script checks for a sessionID cookie. if not found it displays a login form. the login form points to another cgi script that handles the login, creates a cookie and redirects back to the shtml page.
my intent was that when redirected back, the ssi would find the new cookie and not post the login form. however, although the login script works (it adds my login to the login database), the cookie doesn't print to the header so it isn't found.
normally i create the cookie with
print $cgi->header(-cookie=>[@cookies]);
but if i do that before the redirect, the resulting page literally shows the redirect path on screen:
"Location: http://www.redirectpage.com"
any suggestions??
thanks.
i have an shtml page calling a perl cgi script through ssi.
the script checks for a sessionID cookie. if not found it displays a login form. the login form points to another cgi script that handles the login, creates a cookie and redirects back to the shtml page.
my intent was that when redirected back, the ssi would find the new cookie and not post the login form. however, although the login script works (it adds my login to the login database), the cookie doesn't print to the header so it isn't found.
normally i create the cookie with
CODE
print $cgi->header(-cookie=>[@cookies]);
but if i do that before the redirect, the resulting page literally shows the redirect path on screen:
"Location: http://www.redirectpage.com"
any suggestions??
thanks.
RE: set cookie and redirect
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
![[noevil] noevil](https://www.tipmaster.com/images/noevil.gif)
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
RE: set cookie and redirect
the redirect occurs in the perl login script.
once the cookie is created (and usually printed to the header) i redirect the perl script back to the shtml page.
how would i include javascript in the perl script to redirect back to the shtml page?
thanks.
RE: set cookie and redirect
- in shtml main page - normal SSI to call 'cookie check' perl script
- if cookie - get username and print welcome message
- if not cookie - print login form
- enter username/password in login form - action calls validation script
- validation script creates cookie then.....
CODE
print "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>";
print "<html><head><title>$page_title</title>";
print "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://www.backtomainpage'>";
print "</HEAD><BODY></BODY></HTML>";
exit;
since it redirects back to the page i started on, the SSI does its thing again, finds the cookie and therefore displays the welcome message instead of the login form.
hopefully this will help others like me who struggle sometimes.
thanks.