Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Cookie and Redirect

Status
Not open for further replies.

NigeW

Programmer
Jun 10, 2002
134
NZ
I am creating an admin tool with username/password authentication.

If the username/password combination are correct I want to set a cookie for the variables and then redirect to the main administratio menu.

My code is :

# Set Redirection page
$url="
$cookie1 = new CGI::Cookie(-name=>'username', -value=>$FORM{"username"});
$cookie2 = new CGI::Cookie(-name=>'password', -value=>$FORM{"password"});

print $query->redirect(-location=> $url, -cookie=>[$cookie1,$cookie2]);

I get an Internal Server error message.

I have set the permissions on the file to 755.

Can anyone see what I'm doing wrong please ??

Thanks

Nige
kiwi-kid
 
What does your error log say?

I have never tried this but you may not be able to set cookies in a redirect (NOT SURE ABOUT THIS!)

If this is the case you should post to a page, set the cookies and have that page then issue the redirect.

I'd do it with the CGI

if(cookiepassword&&cookieusername) { redirect }
else { set the cookie info after checking login }

Thats psuedo-code :)
 
I've finally figured it out - here's my code :

my $query = new CGI;

my $Redirect = '
$cookie1 = $query->cookie(-name=>'username', -value=> $uname);

$cookie2 = $query->cookie(-name=>'password', -value=> $pw);

print $query->redirect(-uri => $Redirect, -cookie => [$cookie1,$cookie2]);

Hope it helps others out who have experienced the same frustrating issues . . .

Nigel Wilson
"kiwi-kid"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top