Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:34:06+00:00 2026-05-31T11:34:06+00:00

I have the following perl script. I need it to invalidate all cookies that

  • 0

I have the following perl script.
I need it to invalidate all cookies that are not in the validCookies hash. Note this is only the upper part of my code, the rest deals with printing all the cookies in the @cookieArray() and that works for me.
Since the right cookies are being set that I need to set manually later on in the code. ATM the code is not invalidating the cookies, anyone see why?

use CGI qw(:standard);
use CGI::Cookie;    


@cookieArray = ();

#hash of cookie names that should not be set to null
%validCookies = ( cName=> 0, cAddress => 0, cCity => 0, cProvince => 0, cPostalCode => 0, cMail => 0, cDate => 0);

%cook = CGI::Cookie->fetch;
foreach $name ($cook){
 if(exists ($validCookies{$name})){

 } else {
   $temp = CGI::Cookie->new(-name=>$name, -value =>"");
   push(@cookieArray, $temp);
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:34:08+00:00Added an answer on May 31, 2026 at 11:34 am

    To invalidate a cookie, you must expire it. The following code expires all except the protected cookie names.

    It is not necessary to use the CGI::Cookie low-level interface. All the functionality is already exposed through the cookie method.

    use strict;
    use warnings FATAL => 'all';
    use CGI qw();
    use Data::Dumper qw(Dumper);
    
    my %protected_names = map { $_ => undef }
        qw(cName cAddress cCity cProvince cPostalCode cMail cDate);
    
    my $cgi = CGI->new;
    print $cgi->header(
        -type => 'text/plain',
        -cookie => [
            map {
                $cgi->cookie(
                    -name => $_,
                    -value => (exists($protected_names{$_})
                        ? $cgi->cookie($_)
                        : q()
                    ),
                )
            } $cgi->cookie
        ],
    );
    print Dumper [$cgi->cookie];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following perl script that works locally given the input parameters. I
I have the following perl script: $myVariable = some value; //... some code ...
I have to maintain the following Perl script: #!/usr/bin/perl -w die Usage: $0 <file1>
I have an interesting problem. I wrote the following perl script to recursively loop
I have a lot of Perl scripts that looks something like the following. What
I have the following regular expression that works fine in perl: Classification:\s([^\n]+?)(?:\sRange:\s([^\n]+?))*(?:\sStructural Integrity:\s([^\n]+))*\n The
I have the following snippet calling a perl script which writes to STDERR and
I have a perl script that writes out an array filled with integers to
I currently have a perl script that imports HTML and converts it to plain
I have a perl script that processes millions of lines of performance data, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.