in reply to Re: auto create cookies
in thread auto create cookies

ok here is my try. but the script keeps redirecting and getting error in browser. i want to set cookies then continue doing other thing on same page

my $val = "xttsyyd6774"; my $link = "http://localhost/test.pl?val=$val"; # main link if ($val) { my $cookie = $cgi->cookie(-name => 'demo', -value => $val, -expires => + '+20m'); print $cgi->redirect(-location =>$link, -cookie =>$cookie); next; # after creating our cookie with one time redirect then continue + do other staffs on page } <p>so after creating cookie and page comes back from redirect then i c +ontinue doing other things on page. but am getting this error</p> <code> This page isn’t working localhost.com redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS

the main solution i want. is to redirect once. if the page is opened

Replies are listed 'Best First'.
Re^3: auto create cookies
by hippo (Archbishop) on Jan 25, 2019 at 12:29 UTC
    i want to set cookies then continue doing other thing on same page

    In which case, don't redirect.

      if i dont redirect cookie failed to set itself

        As a counter-example showing this not to be true, here is an SSCCE. Enjoy.

        #!/usr/bin/perl -T use strict; use warnings; use CGI::Lite (); my $now = localtime (time ()); my $cgi = CGI::Lite->new; # Retrieve existing cookies my $cookies = $cgi->parse_cookies; my $oldcookie = defined ($cookies) ? $cookies->{bigup401} : 'not set'; # Set new cookie print "Set-Cookie: bigup401=$now\nContent-Type: text/html\n\n"; # Print the page print <<EOT; <p>Previous cookie value was $oldcookie<br /> New cookie value is $now</p> <p><a href="$ENV{REQUEST_URI}">Get next one</a>.</p> EOT exit;