="4.1.0"){ // register_globals が off のため extract($_POST); extract($_GET); extract($_SERVER); } // URL? 以降の因数定義 if(!isset($mode)){ $mode=""; } switch($mode){ case 'regist': regist(); break; // データ入力処理 case 'delete': delete(); break; // データ削除処理 } main(); // メイン関数 // データ入力処理 function regist(){ global $no, $name, $email, $subject, $message, $logfile; global $max_log, $REQUEST_METHOD; // POST以外のリクエストを禁止 if($REQUEST_METHOD != "POST"){ error("不正な投稿をしないで下さい"); } if (!$_POST["name"]){ error("名前が入力されていません"); } if (!$_POST["message"]){ error("内容が入力されていません"); } // タグ禁止処理 $name = convstr($name); $email = convstr($email); $subject = convstr($subject); $message = convstr($message); $date = gmdate( "Y年m月d日(D) H:i",time()+9*60*60);// 時間の取得 if(file_exists($logfile)) $data = file($logfile); // データの読み込み else $data = NULL; if(sizeof($data) < 1){ // データにNoを付けて配列に格納 $no = 1; $nname = ""; $nmessage = ""; // 初期化 }else{ list($nno, $nname, $nemail, $nsubject, $nmessage, $ndate) = split("<>", $data[0]); $no = $nno + 1; } if($name != $nname || $message != $nmessage){ // 2重投稿判定 // 連結 $new_data = implode("<>", array($no, $name, $email, $subject, $message, $date)); //'w+' - 読みこみ・書きこみ用にオープンします。 $fp = fopen($logfile, "w+"); flock($fp, LOCK_EX); fputs($fp, "$new_data\n"); if($max_log <= sizeof($data)){ // 最大記録数の調整 $max = $max_log - 1; }else{ $max = sizeof($data); } for($i = 0; $i < $max; $i++){ // 残りのデータの書きこみ fputs($fp, $data[$i]); } flock($fp, LOCK_UN); fclose($fp); } } // データ削除処理 function delete(){ global $pass, $apass, $logfile, $del; if($apass != $pass){ error("パスワードが違います !"); } if(file_exists($logfile) && ($del != "") && ($pass != "")){ $delfile = file($logfile); $fp = fopen($logfile, "w"); flock($fp, LOCK_EX); for($i = 0; $i < sizeof($delfile); $i ++){ list($no, $name, $email,$subject, $message, $date) = split("<>", $delfile[$i]); if ($del != $no) { fputs($fp, $delfile[$i]); } } flock($fp, LOCK_UN); fclose($fp); } } // エラー作業 function error($msg){ global $error_line; $temp = str_replace("" ,"$msg" ,"$error_line"); print "$temp"; // 画面に表示する exit; } // メイン関数 function main(){ global $max_num, $max_log, $PHP_SELF, $logfile, $main_line, $list_line; if(!isset($next)) $next = 0; // 変数がセットされているか if(file_exists($logfile)) $data = file($logfile); // データの読み込み else $data = NULL; $count = count($data); // ファイルのデータ数 $start = $next * $max_num; $end = $start + $max_num; if($end > $count) $end = $count; // テンプレートにデータを埋め込む $list = ""; for($i = $start; $i < $end; $i ++){ list($no, $name, $email,$subject, $message, $date) = split("<>", $data[$i]); $temp = $list_line; $temp = str_replace("" ,"$no" ,"$temp"); $temp = str_replace("" ,"$name" ,"$temp"); $temp = str_replace("" ,"$email" ,"$temp"); $temp = str_replace("" ,"$message" ,"$temp"); $temp = str_replace("" ,"$subject" ,"$temp"); $temp = str_replace("" ,"$date" ,"$temp"); $list = $list . $temp; } $main_line = str_replace("" ,"$list" ,"$main_line"); $main_line = str_replace("","$PHP_SELF","$main_line"); print "$main_line"; // 画面に表示する exit; } ?>