I did the same thing in PHP. How to use jquery-cookie Perl: How to use cookies PHP: How to use cookies Python3: How to use cookies
Send cookies
cookie_put.rb
#! /usr/bin/ruby
#
# cookie_put.rb
#
#
puts "Set-Cookie: message='Good Morning';\n"
puts "Set-Cookie: aa='Good morning.';\n"
puts "Set-Cookie: bb='It's sunny today.';\n"
puts "Set-Cookie: cc='Hello';\n"
puts 'Content-Type: text/html',"\n"
puts "\n"
puts "<!DOCTYPE html>"
puts "<html lang=\"ja\">"
puts "<head>"
puts "<title>cookie put</title>"
puts "</head>"
puts "<body>"
puts "cookie_put.rb<p />"
puts "Aug/15/2020<p/>"
puts "</body>"
puts "</html>"
Check cookies
cookie_get.rb
#! /usr/bin/ruby
#
# cookie_get.rb
#
cookie = Hash.new
ENV['HTTP_COOKIE'].split(/;\s/).each do |bo|
mo = bo.split(/=/)
cookie[mo[0]] = mo[1]
end
puts "Content-type: text/html\n\n"
puts "<!DOCTYPE html>"
puts "<html lang=\"ja\">"
puts "<head>"
puts "<meta http-equiv=\"CONTENT-TYPE\" content=\"text/html; charset=utf-8\" />"
puts "<title>Cookie Test</title></head>"
puts "<body>"
puts "Cookie Test<p />"
# puts cookie
cookie.each {|key, value|
puts key,":",value,"<p />"
}
puts "</body></html>"
Recommended Posts