×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

set cookie and redirect

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

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

You can always use a javascript redirect.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
noevil
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

(OP)
how would that work?
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

(OP)
i found a solution - i don't know if it is technically correct, but it works.

- 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 $cgi->header(-cookie=>[@cookies]);
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close