訪問回数(クッキー)
#! /usr/local/bin/ruby require "cgi" cgi = CGI.new # Cookieデータ取得 count = cgi.cookies['count'].first count = count.to_i + 1 # Cookieデータ作成 life = 30 * 24 * 60 * 60 expires = Time.now + life cookies = [ CGI::Cookie::new({ 'name' => 'count', 'value' => count.to_s, 'expires' => expires, }), ] cgi.out("cookie" => cookies) do " <html> <head> <title>訪問回数</title> </head> <body> #{count}回目の訪問<br> </body> </html> " end exit
〔 実行する 〕