{
    "content": [
        {
            "type": "text",
            "text": "# CGI::Simple::Cookie (perldoc)\n\n## NAME\n\nCGI::Simple::Cookie - Interface to HTTP cookies\n\n## SYNOPSIS\n\nuse CGI::Simple::Standard qw(header);\nuse CGI::Simple::Cookie;\n# Create new cookies and send them\n$cookie1 = CGI::Simple::Cookie->new( -name=>'ID', -value=>123456 );\n$cookie2 = CGI::Simple::Cookie->new( -name=>'preferences',\n-value=>{ font => Helvetica,\nsize => 12 }\n);\nprint header( -cookie=>[$cookie1,$cookie2] );\n# fetch existing cookies\n%cookies = CGI::Simple::Cookie->fetch;\n$id = $cookies{'ID'}->value;\n# create cookies returned from an external source\n%cookies = CGI::Simple::Cookie->parse($ENV{COOKIE});\n\n## DESCRIPTION\n\nCGI::Simple::Cookie is an interface to HTTP/1.1 cookies, a mechanism that allows Web servers to\nstore persistent information on the browser's side of the connection. Although\nCGI::Simple::Cookie is intended to be used in conjunction with CGI::Simple (and is in fact used\nby it internally), you can use this module independently.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (13 subsections)\n- **AUTHOR INFORMATION**\n- **BUGS**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "CGI::Simple::Cookie",
        "section": "",
        "mode": "perldoc",
        "summary": "CGI::Simple::Cookie - Interface to HTTP cookies",
        "synopsis": "use CGI::Simple::Standard qw(header);\nuse CGI::Simple::Cookie;\n# Create new cookies and send them\n$cookie1 = CGI::Simple::Cookie->new( -name=>'ID', -value=>123456 );\n$cookie2 = CGI::Simple::Cookie->new( -name=>'preferences',\n-value=>{ font => Helvetica,\nsize => 12 }\n);\nprint header( -cookie=>[$cookie1,$cookie2] );\n# fetch existing cookies\n%cookies = CGI::Simple::Cookie->fetch;\n$id = $cookies{'ID'}->value;\n# create cookies returned from an external source\n%cookies = CGI::Simple::Cookie->parse($ENV{COOKIE});",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 18,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 59,
                "subsections": [
                    {
                        "name": "Creating New Cookies",
                        "lines": 40
                    },
                    {
                        "name": "Sending the Cookie to the Browser",
                        "lines": 29
                    },
                    {
                        "name": "Recovering Previous Cookies",
                        "lines": 24
                    },
                    {
                        "name": "Manipulating Cookies",
                        "lines": 5
                    },
                    {
                        "name": "name",
                        "lines": 5
                    },
                    {
                        "name": "value",
                        "lines": 9
                    },
                    {
                        "name": "domain",
                        "lines": 2
                    },
                    {
                        "name": "path",
                        "lines": 2
                    },
                    {
                        "name": "expires",
                        "lines": 2
                    },
                    {
                        "name": "max_age",
                        "lines": 2
                    },
                    {
                        "name": "secure",
                        "lines": 2
                    },
                    {
                        "name": "httponly",
                        "lines": 2
                    },
                    {
                        "name": "samesite",
                        "lines": 2
                    }
                ]
            },
            {
                "name": "AUTHOR INFORMATION",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "CGI::Simple::Cookie - Interface to HTTP cookies\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use CGI::Simple::Standard qw(header);\nuse CGI::Simple::Cookie;\n\n# Create new cookies and send them\n$cookie1 = CGI::Simple::Cookie->new( -name=>'ID', -value=>123456 );\n$cookie2 = CGI::Simple::Cookie->new( -name=>'preferences',\n-value=>{ font => Helvetica,\nsize => 12 }\n);\nprint header( -cookie=>[$cookie1,$cookie2] );\n\n# fetch existing cookies\n%cookies = CGI::Simple::Cookie->fetch;\n$id = $cookies{'ID'}->value;\n\n# create cookies returned from an external source\n%cookies = CGI::Simple::Cookie->parse($ENV{COOKIE});\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "CGI::Simple::Cookie is an interface to HTTP/1.1 cookies, a mechanism that allows Web servers to\nstore persistent information on the browser's side of the connection. Although\nCGI::Simple::Cookie is intended to be used in conjunction with CGI::Simple (and is in fact used\nby it internally), you can use this module independently.\n\nFor full information on cookies see:\n\nhttp://tools.ietf.org/html/rfc2109\nhttp://tools.ietf.org/html/rfc2965\n\nUSING CGI::Simple::Cookie\nCGI::Simple::Cookie is object oriented. Each cookie object has a name and a value. The name is\nany scalar value. The value is any scalar or array value (associative arrays are also allowed).\nCookies also have several optional attributes, including:\n\n1. expiration date\nThe expiration date tells the browser how long to hang on to the cookie. If the cookie\nspecifies an expiration date in the future, the browser will store the cookie information in\na disk file and return it to the server every time the user reconnects (until the expiration\ndate is reached). If the cookie species an expiration date in the past, the browser will\nremove the cookie from the disk file. If the expiration date is not specified, the cookie\nwill persist only until the user quits the browser.\n\n2. domain\nThis is a partial or complete domain name for which the cookie is valid. The browser will\nreturn the cookie to any host that matches the partial domain name. For example, if you\nspecify a domain name of \".capricorn.com\", then the browser will return the cookie to web\nservers running on any of the machines \"www.capricorn.com\", \"ftp.capricorn.com\",\n\"feckless.capricorn.com\", etc. Domain names must contain at least two periods to prevent\nattempts to match on top level domains like \".edu\". If no domain is specified, then the\nbrowser will only return the cookie to servers on the host the cookie originated from.\n\n3. path\nIf you provide a cookie path attribute, the browser will check it against your script's URL\nbefore returning the cookie. For example, if you specify the path \"/cgi-bin\", then the\ncookie will be returned to each of the scripts \"/cgi-bin/tally.pl\", \"/cgi-bin/order.pl\", and\n\"/cgi-bin/customerservice/complain.pl\", but not to the script \"/cgi-private/siteadmin.pl\".\nBy default, the path is set to \"/\", so that all scripts at your site will receive the\ncookie.\n\n4. secure flag\nIf the \"secure\" attribute is set, the cookie will only be sent to your script if the CGI\nrequest is occurring on a secure channel, such as SSL.\n\n5. HttpOnly flag\nIf the \"httponly\" attribute is set, the cookie will only be accessible through HTTP\nRequests. This cookie will be inaccessible via JavaScript (to prevent XSS attacks).\n\nSee this URL for more information including supported browsers:\n\n<http://www.owasp.org/index.php/HTTPOnly>\n\n6. samesite flag\nAllowed settings are \"Strict\", \"Lax\" and \"None\".\n\nAs of April 2018, support is limited mostly to recent releases of Chrome and Opera.\n\n<https://tools.ietf.org/html/draft-west-first-party-cookies-07>\n",
                "subsections": [
                    {
                        "name": "Creating New Cookies",
                        "content": "$c = CGI::Simple::Cookie->new( -name    =>  'foo',\n-value    =>  'bar',\n-expires  =>  '+3M',\n-max-age  =>  '+3M',\n-domain   =>  '.capricorn.com',\n-path     =>  '/cgi-bin/database',\n-secure   =>  1,\n-samesite =>  'Lax',\n);\n\nCreate cookies from scratch with the new method. The -name and -value parameters are required.\nThe name must be a scalar value. The value can be a scalar, an array reference, or a hash\nreference. (At some point in the future cookies will support one of the Perl object\nserialization protocols for full generality).\n\n-expires accepts any of the relative or absolute date formats recognized by CGI::Simple, for\nexample \"+3M\" for three months in the future. See CGI::Simple's documentation for details.\n\n-max-age accepts the same data formats as -expires, but sets a relative value instead of an\nabsolute like -expires. This is intended to be more secure since a clock could be changed to\nfake an absolute time. In practice, as of 2011, \"-max-age\" still does not enjoy the widespread\nsupport that \"-expires\" has. You can set both, and browsers that support \"-max-age\" should\nignore the \"Expires\" header. The drawback to this approach is the bit of bandwidth for sending\nan extra header on each cookie.\n\n-domain points to a domain name or to a fully qualified host name. If not specified, the cookie\nwill be returned only to the Web server that created it.\n\n-path points to a partial URL on the current server. The cookie will be returned to all URLs\nbeginning with the specified path. If not specified, it defaults to '/', which returns the\ncookie to all pages at your site.\n\n-secure if set to a true value instructs the browser to return the cookie only when a\ncryptographic protocol is in use.\n\n-httponly if set to a true value, the cookie will not be accessible via JavaScript.\n\n-samesite may be \"Lax\", \"Strict\" or \"None\" and is an evolving part of the standards for cookies.\nPlease refer to current documentation regarding it.\n"
                    },
                    {
                        "name": "Sending the Cookie to the Browser",
                        "content": "Within a CGI script you can send a cookie to the browser by creating one or more Set-Cookie:\nfields in the HTTP header. Here is a typical sequence:\n\n$c = CGI::Simple::Cookie->new( -name    =>  'foo',\n-value   =>  ['bar','baz'],\n-expires =>  '+3M'\n);\n\nprint \"Set-Cookie: $c\\n\";\nprint \"Content-Type: text/html\\n\\n\";\n\nTo send more than one cookie, create several Set-Cookie: fields. Alternatively, you may\nconcatenate the cookies together with \"; \" and send them in one field.\n\nIf you are using CGI::Simple, you send cookies by providing a -cookie argument to the header()\nmethod:\n\nprint header( -cookie=>$c );\n\nModperl users can set cookies using the request object's headerout() method:\n\n$r->headerout('Set-Cookie',$c);\n\nInternally, Cookie overloads the \"\" operator to call its asstring() method when incorporated\ninto the HTTP header. asstring() turns the Cookie's internal representation into an\nRFC-compliant text representation. You may call asstring() yourself if you prefer:\n\nprint \"Set-Cookie: \",$c->asstring,\"\\n\";\n"
                    },
                    {
                        "name": "Recovering Previous Cookies",
                        "content": "%cookies = CGI::Simple::Cookie->fetch;\n\nfetch returns an associative array consisting of all cookies returned by the browser. The keys\nof the array are the cookie names. You can iterate through the cookies this way:\n\n%cookies = CGI::Simple::Cookie->fetch;\nforeach (keys %cookies) {\ndosomething($cookies{$});\n}\n\nIn a scalar context, fetch() returns a hash reference, which may be more efficient if you are\nmanipulating multiple cookies.\n\nCGI::Simple uses the URL escaping methods to save and restore reserved characters in its\ncookies. If you are trying to retrieve a cookie set by a foreign server, this escaping method\nmay trip you up. Use rawfetch() instead, which has the same semantics as fetch(), but performs\nno unescaping.\n\nYou may also retrieve cookies that were stored in some external form using the parse() class\nmethod:\n\n$COOKIES = `cat /usr/tmp/Cookiestash`;\n%cookies = CGI::Simple::Cookie->parse($COOKIES);\n"
                    },
                    {
                        "name": "Manipulating Cookies",
                        "content": "Cookie objects have a series of accessor methods to get and set cookie attributes. Each accessor\nhas a similar syntax. Called without arguments, the accessor returns the current value of the\nattribute. Called with an argument, the accessor changes the attribute and returns its new\nvalue.\n"
                    },
                    {
                        "name": "name",
                        "content": "Get or set the cookie's name. Example:\n\n$name = $c->name;\n$newname = $c->name('fred');\n"
                    },
                    {
                        "name": "value",
                        "content": "Get or set the cookie's value. Example:\n\n$value = $c->value;\n@newvalue = $c->value(['a','b','c','d']);\n\nvalue() is context sensitive. In a list context it will return the current value of the\ncookie as an array. In a scalar context it will return the first value of a multivalued\ncookie.\n"
                    },
                    {
                        "name": "domain",
                        "content": "Get or set the cookie's domain.\n"
                    },
                    {
                        "name": "path",
                        "content": "Get or set the cookie's path.\n"
                    },
                    {
                        "name": "expires",
                        "content": "Get or set the cookie's expiration time.\n"
                    },
                    {
                        "name": "max_age",
                        "content": "Get or set the cookie's maximum age.\n"
                    },
                    {
                        "name": "secure",
                        "content": "Get or set the cookie's secure flag.\n"
                    },
                    {
                        "name": "httponly",
                        "content": "Get or set the cookie's HttpOnly flag.\n"
                    },
                    {
                        "name": "samesite",
                        "content": "Get or set the cookie's samesite value.\n"
                    }
                ]
            },
            "AUTHOR INFORMATION": {
                "content": "Original version copyright 1997-1998, Lincoln D. Stein. All rights reserved. Originally\ncopyright 2001 Dr James Freeman <jfreeman@tassie.net.au> This release by Andy Armstrong\n<andy@hexten.net>\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nAddress bug reports and comments to: andy@hexten.net\n",
                "subsections": []
            },
            "BUGS": {
                "content": "This section intentionally left blank :-)\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "CGI::Carp, CGI::Simple\n",
                "subsections": []
            }
        }
    }
}