Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1339 Is it possible to set a cookie and then redirect a return visitor to a different url all using cgi?

irt.org | Knowledge Base | CGI | Q1339 [ previous next ]

Q1339 Is it possible to set a cookie and then redirect a return visitor to a different url all using cgi?

Try:

#! /usr/bin/perl -w

use CGI qw(:cgi);

my $q = CGI->new();
my $cookie = $q->cookie(
                        -name    => 'yummy_cookie',
                        -value   => 'chocolate chip',
                        -domain  => '.irt.org',
                        -expires => '+10d',
                        -path    => '/'
                       );
print $q->redirect(
                   -url    => 'http://www.irt.org/index.htm',
                   -cookie => $cookie
                  );

__END__

If you leave out the "-domain", and "-path", then they will default to current values. The above example will be returned to all servers in the irt.org domain.

If you leave out the "-expires", then the cookie will expire when the user closes their browser. The above expires after 10 days.

See "perldoc CGI" for detailed info.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.