CGI(Ruby)
お問い合わせ Mail
PageMenu
Q/A & MB
SeoRegister
ColorChart ①
ColorChart ②
ColorChart ③
Site Home
Site PageMAP
SEO Register
Color[1]
Color[2]
Color[3]
Info Blog
Mail Form
カレンダー
サンプル ⇒
【カレンダー】
下の欄のソーステキストを、拡張子「.cgi」にペーストして、アップし、ブラウザで見る。
#! /usr/local/bin/ruby today = Time.now print "Content-type: text/html; charset=Shift_JIS\n\n" print <<END <html> <head> <title>#{today.year}年カレンダー</title> </head> <body bgcolor="mintcream"> <table align="center" cellpadding="4"> <caption style="font-size:large">#{today.year}年</caption> END days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 月の日数(うるう年の2月は+1) days[1] += 1 if today.year % 4 == 0 and today.year % 100 != 0 or today.year % 400 == 0 for m in 1..12 # カレンダー表示(1月~12月) startday = Time.local(today.year, m, 1) # 1日 endday = days[m - 1] # 最後の日 print "<tr>\n" if m % 3 == 1 print <<" END" <td valign="top"> <table border="0" bordercolor="#ffefd5" cellspacing="0" cellpadding="4"> <tr> <th colspan="7">#{m}<span style="font-size:xx-small">月</span></th> </tr> <tr> <td align="center" style="font-size:xx-small;color:red">日</td> <td align="center" style="font-size:xx-small">月</td> <td align="center" style="font-size:xx-small">火</td> <td align="center" style="font-size:xx-small">水</td> <td align="center" style="font-size:xx-small">木</td> <td align="center" style="font-size:xx-small">金</td> <td align="center" style="font-size:xx-small;color:seagreen">土</font></td> </tr> END count = 0 i = 0 while i < startday.wday # 1日までの空欄 print "<tr>" if count % 7 == 0 print "<td> </td>" count += 1 i += 1 end i = 1 while i <= endday # 日付を書き込む print "<tr>" if count % 7 == 0 print "<td align=\"right\"" print " style=\"color:red\"" if count % 7 == 0 print " style=\"color:seagreen\"" if count % 7 == 6 print ">" print i print "</td>" count += 1 print "</tr>\n" if count % 7 == 0 i += 1 end while count % 7 != 0 # 最後の日からの空欄 print "<td> </td>" count += 1 print "</tr>\n" if count % 7 == 0 end print <<" END" </table> </td> END print "</tr>\n" if m % 3 == 0 end print <<END </table> </body> </html> END exit
訪問回数(クッキー・カウンター)
参考例⇒ 「
【サンプル】
」 色やサイズをアレンジしよう♪ 「.cgi」ファイルを作成。
#! /usr/local/bin/ruby today = Time.now print "Content-type: text/html; charset=Shift_JIS\n\n" print <<END <html> <head> <title>#{today.year}年カレンダー</title> </head> <body bgcolor="mintcream"> <table align="center" cellpadding="4"> <caption style="font-size:large">#{today.year}年</caption> END days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 月の日数(うるう年の2月は+1) days[1] += 1 if today.year % 4 == 0 and today.year % 100 != 0 or today.year % 400 == 0 for m in 1..12 # カレンダー表示(1月~12月) startday = Time.local(today.year, m, 1) # 1日 endday = days[m - 1] # 最後の日 print "<tr>\n" if m % 3 == 1 print <<" END" <td valign="top"> <table border="0" bordercolor="#ffefd5" cellspacing="0" cellpadding="4"> <tr> <th colspan="7">#{m}<span style="font-size:xx-small">月</span></th> </tr> <tr> <td align="center" style="font-size:xx-small;color:red">日</td> <td align="center" style="font-size:xx-small">月</td> <td align="center" style="font-size:xx-small">火</td> <td align="center" style="font-size:xx-small">水</td> <td align="center" style="font-size:xx-small">木</td> <td align="center" style="font-size:xx-small">金</td> <td align="center" style="font-size:xx-small;color:seagreen">土</font></td> </tr> END count = 0 i = 0 while i < startday.wday # 1日までの空欄 print "<tr>" if count % 7 == 0 print "<td> </td>" count += 1 i += 1 end i = 1 while i <= endday # 日付を書き込む print "<tr>" if count % 7 == 0 print "<td align=\"right\"" print " style=\"color:red\"" if count % 7 == 0 print " style=\"color:seagreen\"" if count % 7 == 6 print ">" print i print "</td>" count += 1 print "</tr>\n" if count % 7 == 0 i += 1 end while count % 7 != 0 # 最後の日からの空欄 print "<td> </td>" count += 1 print "</tr>\n" if count % 7 == 0 end print <<" END" </table> </td> END print "</tr>\n" if m % 3 == 0 end print <<END </table> </body> </html> END exit
時刻によって挨拶文を変える
表示例; 《
挨拶
》
深夜や早朝など変化を付けたりネ♪
拡張子「.cgi」にペースト。
#! /usr/local/bin/ruby day = Time.now #日時取得 h = day.hour #時間 if h >= 3 and h < 10 msg = "おはようございます。" elsif h >= 10 and h < 18 msg = "こんにちは。" else msg = "こんばんは。" end print "Content-type: text/html\n\n" print <<END <html> <head> <title>時刻によって挨拶文を変える</title> </head> <body> #{msg}<br> </body> </html> END exit
ホームページ作成日記
ページマップ リスト
「CGI(Perl)」
「CGI(Ruby)」
CGI(Python)
スタイルシート(CSS)
その他便利等1
その他便利等2
.htaccess
HTMLソース
JavaScript
カラーチャート【1】
カラーチャート【2】
カラーチャート【3】
Page Menu
登録と投稿 SiteLinkRegister
PCとHPとetcを質問 掲示板
CategoryLinkRank
パーソナルマイリンク
↑