0 Replies - 1622 Views - Last Post: 26 September 2008 - 09:44 PM

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Creating cookies in Perl

Posted 26 September 2008 - 09:44 PM

Description: This is a small snippet to create a cookie then send it to the header using the header() method. Then we turn right around and get the cookie so we can read it's contents
#  PROGRAM:	set-cookie.cgi
#  PURPOSE:	How to set a simple cookie with Perl & CGI 
#               using the CGI.pm module.

#create a new CGI object
use CGI;
$cgi_query = new CGI;

#use cookie() to create a new cookie
$cookie = $cgi_query->cookie(-name=>'SITE_COOKIE',

#create the HTTP header and print the doc type
print $cgi_query->header(-cookie=>$cookie);

#give page a title and a simple header
print $cgi_query->start_html('My test set-cookie.cgi program');
print $cgi_query->h3('Your cookie is set');

#now end the page
print $cgi_query->end_html;

Is This A Good Question/Topic? 0
  • +

Page 1 of 1