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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write cookie and redirect

Status
Not open for further replies.

Extension

Programmer
Joined
Nov 3, 2004
Messages
311
Location
CA
Hi,

I'm trying to write a cookie and then redirect the user to another url and it's not working. It will redirect, but not write the cookie. I'm running IIS5.

Code:
print $cgi->redirect( -cookie=>$cookie, -url=>"hindex.cgi?action=adm");

Thank you in advance
 
Seperate the CGI processes
Code:
# send the cookie
print $cgi->header( -cookie => $cookie );

# redirect the user
print $cgi->redirect( -uri => 'index.cgi?action=adm' );

M. Brooks
 

I've tried processing them separately but it's still not writing the cookie.

 
FYI: I'm getting the following error:

Code:
Status: 302 Moved location: hindex.cgi?action=adm
 
I'm not sure you can redirect after writing the header information.
Code:
print $cgi->redirect( -uri => 'index.cgi?action=adm[COLOR=red]&init=1[/color]' );
and in index.cgi
Code:
if ( exists ($q->param('init')) {
   write_cookie ($cookie);
}
Just a thought, and not tested ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
My personal preference is to always use mod_perl:

Code:
# Set Cookie
my $cookie = new CGI::Cookie(@data);
Apache->request->headers_out->add('Set-Cookie' => $cookie);

# Redirect to new location
Apache->request->headers_out->add( Refresh => "0;URL=$redirect_url" );

If you're searching for a temporary substitute, you could always use javascript instead.

Code:
<script language="JavaScript">
location.href = "/yourSpecialHappyPlace.html";
</script>

Otherwise, I've got no advice. I hate cookies. Pains in the ass that I prefer to never have to think about, and have avoided for 4 years until now. You bastards! [mad]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top