Commit ceca82c6 authored by 君塚 悠's avatar 君塚 悠

プログラム修正(コメント追記)

parent 18afeb0e
<!-- helloworld -->
<html> <html>
<head> <head>
<title>さぁ、始まりです!</title> <title>さぁ、始まりです!</title>
......
<!-- 氏名を入力するフォーム画面 -->
<html> <html>
<head> <head>
<title>フォーム情報を取得する</title> <title>フォーム情報を取得する</title>
......
<!-- input.phpにて入力された氏名を出力する -->
<html> <html>
<head> <head>
<title>フォーム情報を取得する</title> <title>フォーム情報を取得する</title>
......
<!-- クエリ情報から、表示する文字列を選択する -->
<html> <html>
<head> <head>
<title>クエリ情報を取得する</title> <title>クエリ情報を取得する</title>
......
<!-- ヘッダの情報を取得し、配列宣言で指定したヘッダ名の値を出力する -->
<html> <html>
<head> <head>
<title>ヘッダ情報の取得</title> <title>ヘッダ情報の取得</title>
</head> </head>
</html> </html>
<body> <body>
<h1 style="background: #CCCCCC">ヘッダ情報の取得</h1> <h1 style="background: #cccccc">ヘッダ情報の取得</h1>
<table border="0"> <table border="0">
<?php <?php
// 欲しいヘッダ情報を指定する
$aryHeader=array("HTTP_USER_AGENT", $aryHeader=array("HTTP_USER_AGENT",
"HTTP_ACEPT_LANGUAGE","HTTP_PEFERER"); "HTTP_ACEPT_LANGUAGE","HTTP_PEFERER");
// 欲しいヘッダ情報名及び欲しいヘッダ情報を出力する
foreach ($aryHeader as $name) { foreach ($aryHeader as $name) {
?> ?>
<rt> <rt>
...@@ -21,7 +24,6 @@ foreach ($aryHeader as $name) { ...@@ -21,7 +24,6 @@ foreach ($aryHeader as $name) {
} }
?> ?>
</table> </table>
</form> </form>
</body> </body>
</html> </html>
\ No newline at end of file
<!-- email情報を送信する -->
<html> <html>
<head> <head>
<title>クッキーでデータを記録する</title> <title>クッキーでデータを記録する</title>
......
<!-- cookie.phpにて送られたemail情報をクッキーで90日の間記録する。 -->
<html> <html>
<head> <head>
<title>クッキーでデータを記録する</title> <title>クッキーでデータを記録する</title>
......
<?php <?php
//おみくじデータの用意 // おみくじデータの用意
$aryTitle=array("大吉","中吉","小吉","吉","凶"); $aryTitle=array("大吉","中吉","小吉","吉","凶");
$aryKuji =array( $aryKuji =array(
"大吉"=>"ラッキー!今日は超ハッピー!!", "大吉"=>"ラッキー!今日は超ハッピー!!",
...@@ -7,9 +7,10 @@ $aryKuji =array( ...@@ -7,9 +7,10 @@ $aryKuji =array(
"小吉"=>"小さな幸せを大事にネ。", "小吉"=>"小さな幸せを大事にネ。",
"吉"=>"今日も無難に良い1日を...", "吉"=>"今日も無難に良い1日を...",
"凶"=>"ムムムな今日は大人しく過ごしましょう。"); "凶"=>"ムムムな今日は大人しく過ごしましょう。");
//おみくじのシャッフル // おみくじのシャッフル
shuffle($aryTitle); shuffle($aryTitle);
// 配列の先頭に来たおみくじを出力する
echo $aryTitle[0], "\n"; echo $aryTitle[0], "\n";
echo $aryKuji[$aryTitle[0]], "\n"; echo $aryKuji[$aryTitle[0]], "\n";
......
...@@ -38,7 +38,10 @@ ...@@ -38,7 +38,10 @@
<!-- </html> --> <!-- </html> -->
<?php <?php
// $answerで指定した数を当てる。
// 指定していない場合は、1~100までの数字でランダムに決定する
// 外れた場合は、数が大きいか小さいかが出力され、
// 再度数字を入力できる。
$answer = 30; $answer = 30;
if (is_null($answer)) { if (is_null($answer)) {
mt_srand(microtime()*1000000); mt_srand(microtime()*1000000);
......
<?php <?php
// カレンダーを作成する
// クエリ情報から年月を特定し、出力する
// 情報に年月の記載が無かった場合は現在の年月にする
if ($_GET['num']=='') { if ($_GET['num']=='') {
$today_year =date("Y"); $today_year =date("Y");
$today_month=date("n"); $today_month=date("n");
...@@ -8,7 +12,9 @@ if ($_GET['num']=='') { ...@@ -8,7 +12,9 @@ if ($_GET['num']=='') {
$today_year = date("Y", $timestamp); $today_year = date("Y", $timestamp);
$today_month =date("n", $timestamp); $today_month =date("n", $timestamp);
} }
// 現在の年月のタイムスタンプを作成
$current = mktime(0, 0, 0, $today_month, 1, $today_year); $current = mktime(0, 0, 0, $today_month, 1, $today_year);
// 初日の曜日
$first_day =date("w",$current); $first_day =date("w",$current);
$last_day = date("t",$current); $last_day = date("t",$current);
?> ?>
...@@ -24,12 +30,17 @@ $last_day = date("t",$current); ...@@ -24,12 +30,17 @@ $last_day = date("t",$current);
</tr> </tr>
<?php <?php
for ($i = 1; $i <= $first_day + $last_day; $i++) { for ($i = 1; $i <= $first_day + $last_day; $i++) {
// 一週間分を書き始めるために改行する
if ($i % 7 == 1) {print ("<tr>");} if ($i % 7 == 1) {print ("<tr>");}
// 初日の曜日より月初めの曜日が若ければ、空白を出力する
if($i > $first_day) { if($i > $first_day) {
print("<td>".($i-$first_day)."</td>"); print("<td>".($i-$first_day)."</td>");
} else { } else {
print("<td> & nbsp;</td>"); print("<td> & nbsp;</td>");
} }
// 一週間分記載できたなら行を終える
if ($i % 7 == 0) {print("</tr>"); } if ($i % 7 == 0) {print("</tr>"); }
} }
?> ?>
......
<!-- メール送信フォームを表示する
入力された情報はsedmail.phpに送られ、
メールが送信される -->
<html> <html>
<head> <head>
<title>10日で覚えるPHP5入門教室(アンケート)</title> <title>10日で覚えるPHP5入門教室(アンケート)</title>
</head> </head>
<body> <body>
<!-- タイトル -->
<h1 style="background: #cccccc"> <h1 style="background: #cccccc">
10日で覚えるPHP5入門教室(アンケート)</h1> 10日で覚えるPHP5入門教室(アンケート)</h1>
<form method="POST" action="sendmail.php"> <form method="POST" action="sendmail.php">
<input type="hidden" name="_email" <input type="hidden" name="_email" value="CQW15204@nifty.com" />
value="CQW15204@nifty.com" /> <input type="hidden" name="_subject" value="10日で覚えるPHP5入門教室" />
<input type="hidden" name="_subject" <input type="hidden" name="_result"
value="10日で覚えるPHP5入門教室" /> value="<?php print($_SERVER['PHP_SELF']);?>" />
<input type="hidden" name="_subject"
value="<?php print($SERVER['PHP']);?>" />
<table border="0"> <table border="0">
<tr> <tr>
<th align="right"名前</th> <th align="right"名前</th>
<td><input type="text" name="_from" <td><input type="text" name="_from" size="20" maxlength="30" /></td>
size="50" maxlength="255" /></td> </tr><tr>
<th align="right"E-Mail:</th>
<td><input type="text" name="_from" size="50" maxlength="255" /></td>
</tr><tr> </tr><tr>
<th align="right" valign="top">自由記入欄:</th> <th align="right" valign="top">自由記入欄:</th>
<td><textarea name="memo" rows="5" cols="50"> <td><textarea name="memo" rows="5" cols="50"></textarea></td>
</textarea></td>
</tr> </tr>
</table </table>
<input type="submit" value="送信" /> <input type="submit" value="送信" />
<input type="reset"valuse="クリア" /> <input type="reset"valuse="クリア" />
</form> </form>
......
<?php <?php
// mail_input.phpから受け取った情報を元に、
// メールを作成、送信する。
// 送信後、mail_input.phpにリダイレクトする。
//
$header_info="Form: ".$_POST['_from']." $header_info="Form: ".$_POST['_from']."
\nContent-Type: text/plain;carset \nContent-Type: text/plain;carset
=ISO-2022-JP\nX-Mailer: PHP/".phpversion(); =ISO-2022-JP\nX-Mailer: PHP/".phpversion();
......
<!-- ファイルをアップロードするためのフォームを表示し、
upload_save.phpに渡す -->
<html> <html>
<head> <head>
<title>ファイルのアップロード</title> <title>ファイルのアップロード</title>
......
<?php <?php
// upload.phpから受け取ったファイルを保存する。
// 保存したファイルの概要を表示する。
$error_flag=FALSE; $error_flag=FALSE;
$name="/\doc/".$_FILES['upload_file']['name']; $name="/\doc/".$_FILES['upload_file']['name'];
//アップロード時に行なうエラーチェック
//アップしようとしているファイルが既にある && 上書き禁止 -> エラー
if (file_exists($name)==TRUE & $_POST['forbidden']==1) { if (file_exists($name)==TRUE & $_POST['forbidden']==1) {
$error_flag=TRUE; $error_flag=TRUE;
$error_msg="同名のファイルが存在します。"; $error_msg="同名のファイルが存在します。";
// $_FILEは[要素名] [情報名]で成り立っており、
// [要素名]は
// <input type="file" name="upload_file size="70"><br /> のname
// 情報名には、name, type, size, tmp_name, errorが存在している。
// errorには、アップロード時に発生したエラーが格納される。
// 以下は、エラーメッセージに
} elseif ($_FILES['upload_file']['error'] != UPLOAD_ERR_OK) { } elseif ($_FILES['upload_file']['error'] != UPLOAD_ERR_OK) {
$error_flag=TRUE; $error_flag=TRUE;
switch ($_FILES['upload']['error']) { switch ($_FILES['upload']['error']) {
...@@ -24,12 +37,16 @@ if (file_exists($name)==TRUE & $_POST['forbidden']==1) { ...@@ -24,12 +37,16 @@ if (file_exists($name)==TRUE & $_POST['forbidden']==1) {
break; break;
} }
} }
// エラーがあった場合、エラーメッセージを表示する。
// 正常であれば、
if ($error_flag) { if ($error_flag) {
print("<div style='color:Red;'>".$error_msg."</div>"); print("<div style='color:Red;'>".$error_msg."</div>");
} else { } else {
move_uploaded_file($_FILES['upload_file']['tmp_name'],$name); move_uploaded_file($_FILES['upload_file']['tmp_name'],$name);
} }
?> ?>
<!-- アップロードされたファイルの概要一覧を出力する -->
<html> <html>
<head> <head>
<title>ファイルのアップロード</title> <title>ファイルのアップロード</title>
...@@ -46,6 +63,8 @@ $o_dir=opendir("./doc/"); ...@@ -46,6 +63,8 @@ $o_dir=opendir("./doc/");
while ($file=readdir($o_dir)) { while ($file=readdir($o_dir)) {
if ($file!="." && $file!="..") { if ($file!="." && $file!="..") {
?> ?>
<!-- ファイル名、ファイル容量、ファイルをアップロードした日付、
ファイルを更新した日付を出力する -->
<tr> <tr>
<td><a href="./doc/<?php print($file); ?>"><?php print($file); ?> </a></td> <td><a href="./doc/<?php print($file); ?>"><?php print($file); ?> </a></td>
<td><?php print(round(filesize("./doc/".$file)/1024)); ?>KB</td> <td><?php print(round(filesize("./doc/".$file)/1024)); ?>KB</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment