Posts

Showing posts from January, 2014

Setting Cookies in Perl (RFC 6265)

Setting Cookies in Perl (RFC 6265) Setting cookies in Perl, can be a pain these days. Specially with lack of clarity upon what to do, and what not to do. Here is a simple, yet compliant way of setting cookies as per RFC 6265. You should not use, CGI::Cookie because it is at present outdated, as it is based on the RFC 2965, which was made obsolete by RFC 6265. More on this here:  http://tools.ietf.org/search/rfc6265 Basically the RFC lays out how browser like your plain old Mozilla, Internet Explorer and Chrome should treat cookies, how to identify them, and what would be their attributes. This is the code we would be using today: Explanation:  Line1 : #!/usr/bin/perl says, where your perl files are located, while -T is for taint mode (a security feature) and w is for warnings. Line2: use strict is a security feature, and is strongly recommended! Line3: use CGI, is needed for your script to use Common Gateway Interface. Line 4: use CGI::Carp qw(fatalsToBrowser);