0 Replies - 1462 Views - Last Post: 26 September 2008 - 09:58 PM

#1 PsychoCoder   User is offline

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

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

Get and read a cookie in Perl

Posted 26 September 2008 - 09:58 PM

Description: In this snippet Im retrieving a cookie named SITE_COOKIE. Change that value to the name of the cookie you're looking forThis snippet will show how to get a cookie by it's name using Perl/CGI with the CGI.pm module
#!/bin/perl
#
#  PROGRAM:	get-cookie.cgi
#
#  PURPOSE:	How to get a cookie with Perl & CGI 
#               using the CGI.pm module.

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

# create the HTTP header
print $cgi_query->header;

# start a document
# then give the document a title
print $cgi_query->start_html('My test get-cookie.cgi program');

# now we retrieve the cookie. 
# We can accmplish this by utilizing
# the cookie() method leaving off 
# the -value parameter
print $cgi_query->h4('Your cookie name is...');
$myCookie = $cgi_query->coookie('SITE_COOKIE');

# now print out the cookie
print "
n";
print $myCookie;
print "
n"; # now end the document print $cgi_query->end_html;


Is This A Good Question/Topic? 0
  • +

Page 1 of 1