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

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;

Replies are listed 'Best First'.
Re^6: auto create cookies
by bigup401 (Pilgrim) on Jan 27, 2019 at 09:13 UTC

    thanks

      have tried the above sample and working. but i wanted to replace exiting cookie name every time i open the page test.cgi. to replace the exiting cookie name. so its like replace exiting cookie on particular page when opened and closed

        like this similar example but not working. it checks for cookies with value and modify it automatically. every time when u execute the script. it modify the cookie with new specified value

        #!/usr/bin/perl use CGI::Cookie; my %cookies = fetch CGI::Cookie; my $new_value = 'modify'; print "Content-type: text/html\n\n"; foreach (keys %cookies) { #change value of NewCookie if($_ eq 'NewCookie') { my $val_cookie = $cookies{'NewCookie'}->value; print "\n value of NewCookie =>" . $val_cookie; $cookies{'NewCookie'}->value($new_value); $cookies{'NewCookie'}->bake; } }
          A reply falls below the community's threshold of quality. You may see it by logging in.