質問編集履歴
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -92,6 +92,90 @@
|
|
92
92
|
```
|
93
93
|
自分がやったのとさほどかわらないのでサイトのまま乗せてます。
|
94
94
|
|
95
|
+
自分の修正版一応エラーは消えてる
|
96
|
+
```
|
97
|
+
<?php
|
98
|
+
$lines = file('bbs2.txt');
|
99
|
+
if(!isset($_POST['write'])){
|
100
|
+
$name = $_COOKIE['name'];
|
101
|
+
}else{
|
102
|
+
if($_POST['write']){
|
103
|
+
$items = explode("\t", $lines[0]);
|
104
|
+
$no = $items[0] + 1;
|
105
|
+
$name = htmlspecialchars($_POST['name']);
|
106
|
+
if (!$name) $name = "名無しさん";
|
107
|
+
$mail = htmlspecialchars($_POST['mail']);
|
108
|
+
$title = htmlspecialchars($_POST['title']);
|
109
|
+
if (!$title) $title = "無題";
|
110
|
+
$contents = htmlspecialchars($_POST['contents']);
|
111
|
+
$contents = str_replace("\r\n", "<br>", $contents);
|
112
|
+
$contents = str_replace("\r", "<br>", $contents);
|
113
|
+
$contents = str_replace("\n", "<br>", $contents);
|
114
|
+
$delkey = htmlspecialchars($_POST['delkey']);
|
115
|
+
$time = date("Y/m/d H:i:s");
|
116
|
+
$expire = time() + 3600 * 24 * 30;
|
117
|
+
setcookie("name", $name, $expire);
|
118
|
+
setcookie("mail", $mail, $expire);
|
119
|
+
setcookie("delkey", $delkey, $expire);
|
120
|
+
$data = "$no\t$name\t$mail\t$title\t$contents\t$delkey\t$time\n";
|
121
|
+
array_unshift($lines, $data);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
if(isset($_POST['delete'])) {
|
125
|
+
for ($i = 0; $i < count($lines); $i++) {
|
126
|
+
$items = explode("\t", $lines[$i]);
|
127
|
+
if ($items[0] == $_POST['delno'] && $items[5] == $_POST['delkey2']) {
|
128
|
+
array_splice($lines, $i, 1);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
if(isset($_POST['write'])){
|
133
|
+
$fp = fopen('bbs2.txt', 'w');
|
134
|
+
foreach($lines as $line) fputs($fp, $line);
|
135
|
+
fclose($fp);
|
136
|
+
}
|
137
|
+
if(isset($_POST['delete'])){
|
138
|
+
$fp = fopen('bbs2.txt', 'w');
|
139
|
+
foreach($lines as $line) fputs($fp, $line);
|
140
|
+
fclose($fp);
|
141
|
+
}
|
142
|
+
?>
|
143
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
144
|
+
<html lang="ja">
|
145
|
+
<head>
|
146
|
+
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
147
|
+
<title>掲示板2</title>
|
148
|
+
</head>
|
149
|
+
<body>
|
150
|
+
<form method="post" action="tes.php">
|
151
|
+
お名前:<input type="text" name="name" value="<?php print $name ?>"><br>
|
152
|
+
メール:<input type="text" name="mail" value="<?php print $mail ?>"><br>
|
153
|
+
題 名:<input type="text" name="title"><br>
|
154
|
+
削除キー:<input type="password" name="delkey" value="<?php print $delkey ?>"><br>
|
155
|
+
<textarea name="contents" cols="60" rows="5"></textarea><br>
|
156
|
+
<input type="submit" name="write" value="送信">
|
157
|
+
<hr>
|
158
|
+
記事番号:<input type="text" name="delno">
|
159
|
+
削除キー: <input type="password" name="delkey2">
|
160
|
+
<input type="submit" name="delete" value="記事削除">
|
161
|
+
</form>
|
162
|
+
<hr>
|
163
|
+
<?php
|
164
|
+
foreach($lines as $line) {
|
165
|
+
$line = rtrim($line);
|
166
|
+
$items = explode("\t", $line);
|
167
|
+
print "No.{$items[0]} ";
|
168
|
+
print "<b>{$items[3]}</b> 投稿者:";
|
169
|
+
if ($items[2]) print "<a href='mailto:{$items[2]}'>";
|
170
|
+
print $items[1];
|
171
|
+
if ($items[2]) print "</a>";
|
172
|
+
print " 投稿時間:{$items[6]}";
|
173
|
+
print "<p>{$items[4]}</p><hr>\n";
|
174
|
+
}
|
175
|
+
?>
|
176
|
+
</body>
|
177
|
+
</html>
|
178
|
+
```
|
95
179
|
###試したこと
|
96
180
|
IFをつけてやりたかったのだがいい条件式が探してみたが見つからなかった。
|
97
181
|
グローバル変数で先に$itemsで配列を作ったがまったく意味なかった。
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,52 +13,79 @@
|
|
13
13
|
|
14
14
|
###該当のソースコード
|
15
15
|
```
|
16
|
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
17
|
-
<html lang="ja">
|
18
|
-
<head>
|
19
|
-
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
20
|
-
<title>掲示板1</title>
|
21
|
-
</head>
|
22
|
-
<body>
|
23
|
-
<form method="post" action="bbs1.php">
|
24
|
-
お名前: <input type="text" name="name"><br>
|
25
|
-
メール: <input type="text" name="mail"><br>
|
26
|
-
題 名: <input type="text" name="title"><br>
|
27
|
-
<textarea name="contents" cols="60" rows="5"></textarea><br>
|
28
|
-
<input type="submit" name="write" value="送信">
|
29
|
-
</form>
|
30
|
-
<hr>
|
31
16
|
<?php
|
32
|
-
$lines = file('
|
17
|
+
$lines = file('bbs2.txt');
|
33
|
-
|
34
18
|
if ($_POST['write']) {
|
19
|
+
$items = explode("\t", $lines[0]);
|
20
|
+
$no = $items[0] + 1;
|
35
21
|
$name = htmlspecialchars($_POST['name']);
|
22
|
+
if (!$name) $name = "名無しさん";
|
36
23
|
$mail = htmlspecialchars($_POST['mail']);
|
37
24
|
$title = htmlspecialchars($_POST['title']);
|
25
|
+
if (!$title) $title = "無題";
|
38
26
|
$contents = htmlspecialchars($_POST['contents']);
|
39
27
|
$contents = str_replace("\r\n", "<br>", $contents);
|
40
28
|
$contents = str_replace("\r", "<br>", $contents);
|
41
29
|
$contents = str_replace("\n", "<br>", $contents);
|
30
|
+
$delkey = htmlspecialchars($_POST['delkey']);
|
42
31
|
$time = date("Y/m/d H:i:s");
|
32
|
+
$expire = time() + 3600 * 24 * 30;
|
33
|
+
setcookie("name", $name, $expire);
|
34
|
+
setcookie("mail", $mail, $expire);
|
35
|
+
setcookie("delkey", $delkey, $expire);
|
43
|
-
$data = "$name\t$mail\t$title\t$contents\t$time\n";
|
36
|
+
$data = "$no\t$name\t$mail\t$title\t$contents\t$delkey\t$time\n";
|
44
37
|
array_unshift($lines, $data);
|
38
|
+
} else {
|
39
|
+
$name = $_COOKIE['name'];
|
40
|
+
$mail = $_COOKIE['mail'];
|
41
|
+
$delkey = $_COOKIE['delkey'];
|
45
42
|
}
|
46
|
-
|
43
|
+
if ($_POST['delete']) {
|
44
|
+
for ($i = 0; $i < count($lines); $i++) {
|
45
|
+
$items = explode("\t", $lines[$i]);
|
46
|
+
if ($items[0] == $_POST['delno'] && $items[5] == $_POST['delkey2']) {
|
47
|
+
array_splice($lines, $i, 1);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
if ($_POST['write'] || $_POST['delete']) {
|
52
|
+
$fp = fopen('bbs2.txt', 'w');
|
53
|
+
foreach($lines as $line) fputs($fp, $line);
|
54
|
+
fclose($fp);
|
55
|
+
}
|
56
|
+
?>
|
57
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
58
|
+
<html lang="ja">
|
59
|
+
<head>
|
60
|
+
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
61
|
+
<title>掲示板2</title>
|
62
|
+
</head>
|
63
|
+
<body>
|
64
|
+
<form method="post" action="bbs2.php">
|
65
|
+
お名前:<input type="text" name="name" value="<?php print $name ?>"><br>
|
66
|
+
メール:<input type="text" name="mail" value="<?php print $mail ?>"><br>
|
67
|
+
題 名:<input type="text" name="title"><br>
|
68
|
+
削除キー:<input type="password" name="delkey" value="<?php print $delkey ?>"><br>
|
69
|
+
<textarea name="contents" cols="60" rows="5"></textarea><br>
|
70
|
+
<input type="submit" name="write" value="送信">
|
71
|
+
<hr>
|
72
|
+
記事番号:<input type="text" name="delno">
|
73
|
+
削除キー: <input type="password" name="delkey2">
|
74
|
+
<input type="submit" name="delete" value="記事削除">
|
75
|
+
</form>
|
76
|
+
<hr>
|
77
|
+
<?php
|
47
78
|
foreach($lines as $line) {
|
48
79
|
$line = rtrim($line);
|
49
80
|
$items = explode("\t", $line);
|
81
|
+
print "No.{$items[0]} ";
|
50
|
-
print "<b>{$items[
|
82
|
+
print "<b>{$items[3]}</b> 投稿者:";
|
51
|
-
if ($items[
|
83
|
+
if ($items[2]) print "<a href='mailto:{$items[2]}'>";
|
52
|
-
print $items[
|
84
|
+
print $items[1];
|
53
|
-
if ($items[
|
85
|
+
if ($items[2]) print "</a>";
|
54
|
-
print "投稿時間:{$items[
|
86
|
+
print " 投稿時間:{$items[6]}";
|
55
|
-
print "<p>{$items[
|
87
|
+
print "<p>{$items[4]}</p><hr>\n";
|
56
88
|
}
|
57
|
-
|
58
|
-
$fp = fopen('bbs1.txt', 'w');
|
59
|
-
foreach($lines as $line) fputs($fp, $line);
|
60
|
-
fclose($fp);
|
61
|
-
|
62
89
|
?>
|
63
90
|
</body>
|
64
91
|
</html>
|
2
エラー文を載せてみた
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,12 @@
|
|
5
5
|
###発生している問題・エラーメッセージ
|
6
6
|
掲示板を作るサイトを見つけまして [ポンクソフト](http://ponk.jp/php/file/bbs1) やってみてたんですがどうやら最初おかしいらしくエラーがでまくります。少しずつ直して後は一番下のprintエラーだけになりました。これがどうも直らないので対処法を教えてください。また最初からおかしいのでこのサイトは信用してはいけないのでしょうか?
|
7
7
|

|
8
|
+
画像は最初の場面で
|
9
|
+
画像の上の部分は全部クリアしました。
|
10
|
+
残ってるエラーは下のやつだけです。
|
11
|
+
Undefined offsetなので調べてみた結果配列がありませんとか言うエラーだと思います。
|
12
|
+
一番最初なのでテキストが空白なのでありませんって言われてエラー文がPRINTされてしまうものだという予想。
|
13
|
+
|
8
14
|
###該当のソースコード
|
9
15
|
```
|
10
16
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
1
画面がおかしかったので修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
投稿したときのNo1の下の空欄が出来てしまうのでどうにかしたい。
|
4
4
|
|
5
5
|
###発生している問題・エラーメッセージ
|
6
|
-
掲示板を作るサイトを見つけまして [ポンクソフト](http://ponk.jp/php/file/bbs1) やってみてたんですがどうやら最初
|
6
|
+
掲示板を作るサイトを見つけまして [ポンクソフト](http://ponk.jp/php/file/bbs1) やってみてたんですがどうやら最初おかしいらしくエラーがでまくります。少しずつ直して後は一番下のprintエラーだけになりました。これがどうも直らないので対処法を教えてください。また最初からおかしいのでこのサイトは信用してはいけないのでしょうか?
|
7
7
|

|
8
8
|
###該当のソースコード
|
9
9
|
```
|