質問編集履歴
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -186,6 +186,174 @@
|
|
186
186
|
|
187
187
|
|
188
188
|
|
189
|
+
自分の修正版一応エラーは消えてる
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
<?php
|
194
|
+
|
195
|
+
$lines = file('bbs2.txt');
|
196
|
+
|
197
|
+
if(!isset($_POST['write'])){
|
198
|
+
|
199
|
+
$name = $_COOKIE['name'];
|
200
|
+
|
201
|
+
}else{
|
202
|
+
|
203
|
+
if($_POST['write']){
|
204
|
+
|
205
|
+
$items = explode("\t", $lines[0]);
|
206
|
+
|
207
|
+
$no = $items[0] + 1;
|
208
|
+
|
209
|
+
$name = htmlspecialchars($_POST['name']);
|
210
|
+
|
211
|
+
if (!$name) $name = "名無しさん";
|
212
|
+
|
213
|
+
$mail = htmlspecialchars($_POST['mail']);
|
214
|
+
|
215
|
+
$title = htmlspecialchars($_POST['title']);
|
216
|
+
|
217
|
+
if (!$title) $title = "無題";
|
218
|
+
|
219
|
+
$contents = htmlspecialchars($_POST['contents']);
|
220
|
+
|
221
|
+
$contents = str_replace("\r\n", "<br>", $contents);
|
222
|
+
|
223
|
+
$contents = str_replace("\r", "<br>", $contents);
|
224
|
+
|
225
|
+
$contents = str_replace("\n", "<br>", $contents);
|
226
|
+
|
227
|
+
$delkey = htmlspecialchars($_POST['delkey']);
|
228
|
+
|
229
|
+
$time = date("Y/m/d H:i:s");
|
230
|
+
|
231
|
+
$expire = time() + 3600 * 24 * 30;
|
232
|
+
|
233
|
+
setcookie("name", $name, $expire);
|
234
|
+
|
235
|
+
setcookie("mail", $mail, $expire);
|
236
|
+
|
237
|
+
setcookie("delkey", $delkey, $expire);
|
238
|
+
|
239
|
+
$data = "$no\t$name\t$mail\t$title\t$contents\t$delkey\t$time\n";
|
240
|
+
|
241
|
+
array_unshift($lines, $data);
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
if(isset($_POST['delete'])) {
|
248
|
+
|
249
|
+
for ($i = 0; $i < count($lines); $i++) {
|
250
|
+
|
251
|
+
$items = explode("\t", $lines[$i]);
|
252
|
+
|
253
|
+
if ($items[0] == $_POST['delno'] && $items[5] == $_POST['delkey2']) {
|
254
|
+
|
255
|
+
array_splice($lines, $i, 1);
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
if(isset($_POST['write'])){
|
264
|
+
|
265
|
+
$fp = fopen('bbs2.txt', 'w');
|
266
|
+
|
267
|
+
foreach($lines as $line) fputs($fp, $line);
|
268
|
+
|
269
|
+
fclose($fp);
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
if(isset($_POST['delete'])){
|
274
|
+
|
275
|
+
$fp = fopen('bbs2.txt', 'w');
|
276
|
+
|
277
|
+
foreach($lines as $line) fputs($fp, $line);
|
278
|
+
|
279
|
+
fclose($fp);
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
?>
|
284
|
+
|
285
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
286
|
+
|
287
|
+
<html lang="ja">
|
288
|
+
|
289
|
+
<head>
|
290
|
+
|
291
|
+
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
292
|
+
|
293
|
+
<title>掲示板2</title>
|
294
|
+
|
295
|
+
</head>
|
296
|
+
|
297
|
+
<body>
|
298
|
+
|
299
|
+
<form method="post" action="tes.php">
|
300
|
+
|
301
|
+
お名前:<input type="text" name="name" value="<?php print $name ?>"><br>
|
302
|
+
|
303
|
+
メール:<input type="text" name="mail" value="<?php print $mail ?>"><br>
|
304
|
+
|
305
|
+
題 名:<input type="text" name="title"><br>
|
306
|
+
|
307
|
+
削除キー:<input type="password" name="delkey" value="<?php print $delkey ?>"><br>
|
308
|
+
|
309
|
+
<textarea name="contents" cols="60" rows="5"></textarea><br>
|
310
|
+
|
311
|
+
<input type="submit" name="write" value="送信">
|
312
|
+
|
313
|
+
<hr>
|
314
|
+
|
315
|
+
記事番号:<input type="text" name="delno">
|
316
|
+
|
317
|
+
削除キー: <input type="password" name="delkey2">
|
318
|
+
|
319
|
+
<input type="submit" name="delete" value="記事削除">
|
320
|
+
|
321
|
+
</form>
|
322
|
+
|
323
|
+
<hr>
|
324
|
+
|
325
|
+
<?php
|
326
|
+
|
327
|
+
foreach($lines as $line) {
|
328
|
+
|
329
|
+
$line = rtrim($line);
|
330
|
+
|
331
|
+
$items = explode("\t", $line);
|
332
|
+
|
333
|
+
print "No.{$items[0]} ";
|
334
|
+
|
335
|
+
print "<b>{$items[3]}</b> 投稿者:";
|
336
|
+
|
337
|
+
if ($items[2]) print "<a href='mailto:{$items[2]}'>";
|
338
|
+
|
339
|
+
print $items[1];
|
340
|
+
|
341
|
+
if ($items[2]) print "</a>";
|
342
|
+
|
343
|
+
print " 投稿時間:{$items[6]}";
|
344
|
+
|
345
|
+
print "<p>{$items[4]}</p><hr>\n";
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
?>
|
350
|
+
|
351
|
+
</body>
|
352
|
+
|
353
|
+
</html>
|
354
|
+
|
355
|
+
```
|
356
|
+
|
189
357
|
###試したこと
|
190
358
|
|
191
359
|
IFをつけてやりたかったのだがいい条件式が探してみたが見つからなかった。
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,49 +28,25 @@
|
|
28
28
|
|
29
29
|
```
|
30
30
|
|
31
|
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
32
|
-
|
33
|
-
<html lang="ja">
|
34
|
-
|
35
|
-
<head>
|
36
|
-
|
37
|
-
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
38
|
-
|
39
|
-
<title>掲示板1</title>
|
40
|
-
|
41
|
-
</head>
|
42
|
-
|
43
|
-
<body>
|
44
|
-
|
45
|
-
<form method="post" action="bbs1.php">
|
46
|
-
|
47
|
-
お名前: <input type="text" name="name"><br>
|
48
|
-
|
49
|
-
メール: <input type="text" name="mail"><br>
|
50
|
-
|
51
|
-
題 名: <input type="text" name="title"><br>
|
52
|
-
|
53
|
-
<textarea name="contents" cols="60" rows="5"></textarea><br>
|
54
|
-
|
55
|
-
<input type="submit" name="write" value="送信">
|
56
|
-
|
57
|
-
</form>
|
58
|
-
|
59
|
-
<hr>
|
60
|
-
|
61
31
|
<?php
|
62
32
|
|
63
|
-
$lines = file('bbs
|
33
|
+
$lines = file('bbs2.txt');
|
64
|
-
|
65
|
-
|
66
34
|
|
67
35
|
if ($_POST['write']) {
|
68
36
|
|
37
|
+
$items = explode("\t", $lines[0]);
|
38
|
+
|
39
|
+
$no = $items[0] + 1;
|
40
|
+
|
69
41
|
$name = htmlspecialchars($_POST['name']);
|
42
|
+
|
43
|
+
if (!$name) $name = "名無しさん";
|
70
44
|
|
71
45
|
$mail = htmlspecialchars($_POST['mail']);
|
72
46
|
|
73
47
|
$title = htmlspecialchars($_POST['title']);
|
48
|
+
|
49
|
+
if (!$title) $title = "無題";
|
74
50
|
|
75
51
|
$contents = htmlspecialchars($_POST['contents']);
|
76
52
|
|
@@ -80,15 +56,101 @@
|
|
80
56
|
|
81
57
|
$contents = str_replace("\n", "<br>", $contents);
|
82
58
|
|
59
|
+
$delkey = htmlspecialchars($_POST['delkey']);
|
60
|
+
|
83
61
|
$time = date("Y/m/d H:i:s");
|
84
62
|
|
63
|
+
$expire = time() + 3600 * 24 * 30;
|
64
|
+
|
65
|
+
setcookie("name", $name, $expire);
|
66
|
+
|
67
|
+
setcookie("mail", $mail, $expire);
|
68
|
+
|
69
|
+
setcookie("delkey", $delkey, $expire);
|
70
|
+
|
85
|
-
$data = "$name\t$mail\t$title\t$contents\t$time\n";
|
71
|
+
$data = "$no\t$name\t$mail\t$title\t$contents\t$delkey\t$time\n";
|
86
72
|
|
87
73
|
array_unshift($lines, $data);
|
88
74
|
|
75
|
+
} else {
|
76
|
+
|
77
|
+
$name = $_COOKIE['name'];
|
78
|
+
|
79
|
+
$mail = $_COOKIE['mail'];
|
80
|
+
|
81
|
+
$delkey = $_COOKIE['delkey'];
|
82
|
+
|
89
83
|
}
|
90
84
|
|
85
|
+
if ($_POST['delete']) {
|
91
86
|
|
87
|
+
for ($i = 0; $i < count($lines); $i++) {
|
88
|
+
|
89
|
+
$items = explode("\t", $lines[$i]);
|
90
|
+
|
91
|
+
if ($items[0] == $_POST['delno'] && $items[5] == $_POST['delkey2']) {
|
92
|
+
|
93
|
+
array_splice($lines, $i, 1);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
if ($_POST['write'] || $_POST['delete']) {
|
102
|
+
|
103
|
+
$fp = fopen('bbs2.txt', 'w');
|
104
|
+
|
105
|
+
foreach($lines as $line) fputs($fp, $line);
|
106
|
+
|
107
|
+
fclose($fp);
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
?>
|
112
|
+
|
113
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
114
|
+
|
115
|
+
<html lang="ja">
|
116
|
+
|
117
|
+
<head>
|
118
|
+
|
119
|
+
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
120
|
+
|
121
|
+
<title>掲示板2</title>
|
122
|
+
|
123
|
+
</head>
|
124
|
+
|
125
|
+
<body>
|
126
|
+
|
127
|
+
<form method="post" action="bbs2.php">
|
128
|
+
|
129
|
+
お名前:<input type="text" name="name" value="<?php print $name ?>"><br>
|
130
|
+
|
131
|
+
メール:<input type="text" name="mail" value="<?php print $mail ?>"><br>
|
132
|
+
|
133
|
+
題 名:<input type="text" name="title"><br>
|
134
|
+
|
135
|
+
削除キー:<input type="password" name="delkey" value="<?php print $delkey ?>"><br>
|
136
|
+
|
137
|
+
<textarea name="contents" cols="60" rows="5"></textarea><br>
|
138
|
+
|
139
|
+
<input type="submit" name="write" value="送信">
|
140
|
+
|
141
|
+
<hr>
|
142
|
+
|
143
|
+
記事番号:<input type="text" name="delno">
|
144
|
+
|
145
|
+
削除キー: <input type="password" name="delkey2">
|
146
|
+
|
147
|
+
<input type="submit" name="delete" value="記事削除">
|
148
|
+
|
149
|
+
</form>
|
150
|
+
|
151
|
+
<hr>
|
152
|
+
|
153
|
+
<?php
|
92
154
|
|
93
155
|
foreach($lines as $line) {
|
94
156
|
|
@@ -96,29 +158,21 @@
|
|
96
158
|
|
97
159
|
$items = explode("\t", $line);
|
98
160
|
|
99
|
-
print "
|
161
|
+
print "No.{$items[0]} ";
|
100
162
|
|
101
|
-
|
163
|
+
print "<b>{$items[3]}</b> 投稿者:";
|
102
164
|
|
103
|
-
print $items[
|
165
|
+
if ($items[2]) print "<a href='mailto:{$items[2]}'>";
|
104
166
|
|
105
|
-
i
|
167
|
+
print $items[1];
|
106
168
|
|
107
|
-
|
169
|
+
if ($items[2]) print "</a>";
|
108
170
|
|
171
|
+
print " 投稿時間:{$items[6]}";
|
172
|
+
|
109
|
-
print "<p>{$items[
|
173
|
+
print "<p>{$items[4]}</p><hr>\n";
|
110
174
|
|
111
175
|
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
$fp = fopen('bbs1.txt', 'w');
|
116
|
-
|
117
|
-
foreach($lines as $line) fputs($fp, $line);
|
118
|
-
|
119
|
-
fclose($fp);
|
120
|
-
|
121
|
-
|
122
176
|
|
123
177
|
?>
|
124
178
|
|
2
エラー文を載せてみた
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,6 +11,18 @@
|
|
11
11
|
掲示板を作るサイトを見つけまして [ポンクソフト](http://ponk.jp/php/file/bbs1) やってみてたんですがどうやら最初おかしいらしくエラーがでまくります。少しずつ直して後は一番下のprintエラーだけになりました。これがどうも直らないので対処法を教えてください。また最初からおかしいのでこのサイトは信用してはいけないのでしょうか?
|
12
12
|
|
13
13
|
![イメージ説明](f0bf9049ae2648993972510b457f1dc7.png)
|
14
|
+
|
15
|
+
画像は最初の場面で
|
16
|
+
|
17
|
+
画像の上の部分は全部クリアしました。
|
18
|
+
|
19
|
+
残ってるエラーは下のやつだけです。
|
20
|
+
|
21
|
+
Undefined offsetなので調べてみた結果配列がありませんとか言うエラーだと思います。
|
22
|
+
|
23
|
+
一番最初なのでテキストが空白なのでありませんって言われてエラー文がPRINTされてしまうものだという予想。
|
24
|
+
|
25
|
+
|
14
26
|
|
15
27
|
###該当のソースコード
|
16
28
|
|
1
画面がおかしかったので修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
###発生している問題・エラーメッセージ
|
10
10
|
|
11
|
-
掲示板を作るサイトを見つけまして [ポンクソフト](http://ponk.jp/php/file/bbs1) やってみてたんですがどうやら最初
|
11
|
+
掲示板を作るサイトを見つけまして [ポンクソフト](http://ponk.jp/php/file/bbs1) やってみてたんですがどうやら最初おかしいらしくエラーがでまくります。少しずつ直して後は一番下のprintエラーだけになりました。これがどうも直らないので対処法を教えてください。また最初からおかしいのでこのサイトは信用してはいけないのでしょうか?
|
12
12
|
|
13
13
|
![イメージ説明](f0bf9049ae2648993972510b457f1dc7.png)
|
14
14
|
|