Setting Cookies and Other HTTP Response Headers : Cookie « CGI « Ruby






Setting Cookies and Other HTTP Response Headers



#!/usr/bin/ruby

require "cgi"
cgi = CGI.new("html3")

cookie = cgi.cookies['yourCookie']
cookie = CGI::Cookie.new('yourCookie', 'hits=0',
                         "last=#{Time.now}") if cookie.empty?

hits = cookie.value[0].split('=')[1]
last = cookie.value[1].split('=')[1]

cookie.value[0] = "hits=#{hits.succ}"
cookie.value[1] = "last=#{Time.now}"

 








Related examples in the same category