0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Perl: クッキーの使い方

Last updated at Posted at 2020-08-14

こちらと同じことを、Perl の CGI で行いました。
jquery-cookie の使い方

クッキーを送る

cookie_put.pl
#! /usr/bin/perl
#
#	cookie_put.pl
#
use strict;
use warnings;
#
print "Set-Cookie: message='Good Morning by Perl';SameSite=None;Secure;\n";
print "Set-Cookie: aa='おはようございます。Perl';SameSite=None;Secure;\n";
print "Set-Cookie: bb=Test_bb by Perl;SameSite=None;Secure;\n";
print "Set-Cookie: cc=Test_cc by Perl;SameSite=None;Secure;\n";
print 'Content-Type: text/html',"\n";
print "\n";
print "\n";
print "<!DOCTYPE html>";
print "<html lang=\"ja\">";
print "<head>";
print "<title>cookie put</title>";
print "</head>";
print "<body>";
print "cookie_put.pl<p />";
print "Aug/14/2020<p/>";
print "</body>";
print "</html>";

クッキーを確認

cookie_get.pl
#! /usr/bin/perl
#
#	cookie_get.pl
#
use strict;
use warnings;
use CGI::Cookie;
 
my %cookies = fetch CGI::Cookie;

my $message = ""; 
my $aa = ""; 
my $bb = ""; 
my $cc = ""; 
if(exists $cookies{'message'}){ $message  = $cookies{'message'}->value; }
if(exists $cookies{'aa'}){ $aa  = $cookies{'aa'}->value; }
if(exists $cookies{'bb'}){ $bb  = $cookies{'bb'}->value; }
if(exists $cookies{'cc'}){ $cc  = $cookies{'cc'}->value; }
 
print "Content-type: text/html\n\n";
print "<!DOCTYPE html>";
print "<html lang=\"ja\">";
print "<head>";
print '<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />';
print "<title>cookie get</title>";
print "</head>";
print "<body>";
print "message: " . $message . "<p />";
print "aa: " . $aa . "<p />";
print "bb: " . $bb . "<p />";
print "cc: " . $cc . "<p />";
print "cookie_get.pl<p />";
print "Aug/14/2020<p/>";
print "</body>";
print "</html>";

Firefox でのクッキーの確認の方法
firefox_cookie.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?