ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
PHP シンプル掲示板 ( ver 1.03 )
日時: 2013/05/01 23:25
名前: lightbox



http://lightbox.on.coocan.jp/download/board.lzh

  投稿データ用テーブル
拡張子:
CREATE TABLE `board` (
  `board_id` bigint not null auto_increment,
  `board_title` varchar(50),
  `board_name` varchar(20),
  `board_pass` varchar(40),
  `board_body` mediumtext,
  `board_create` datetime,
  `board_update` datetime,
  `board_delflg` varchar(1),
  PRIMARY KEY (`board_id`)
)
  連続投稿禁止用テーブル
拡張子:
CREATE TABLE `access` (
  `access_ip` varchar(15),
  `access_time` int,
  PRIMARY KEY (`access_ip`)
)
  実装済み
拡張子:
◎ 同一投稿の禁止
◎ 削除時は、`board_delflg` に 'D' をセットする
◎ 名前が未入力の場合の処理
◎ 名前とパスワードをクッキーで復帰
◎ 入力された HTML が反映されないようにする
◎ 連続投稿の禁止( 対アプリ投稿 )
  要修正内容
拡張子:
◎ 変更時エラーが出た場合、元の状態に復帰していない
◎ 投稿データのループ部分を、外部ファイル取得の埋め込み型にする
◎ クッキーの有効期限を、ソースコード先頭で設定する
◎ サーバーのエラーチェックを model で関数化する
◎ entry.php の初期位置を画面右上にする
◎ 更新後は全てリダイレクトにし、メッセージ等の画面コントロールをリダイレクト後に行う
  未実装
拡張子:
◎ SQLおよびメッセージを外部ファイル化する
◎ タイトルおよび本文に対する禁止文字列フィルタ
◎ 投稿参照機能
◎ ページ処理
◎ 検索処理
◎ 添付ファイル機能( 含ファイルアップロード )
◎ URL リンク化( 正規表現 )
◎ テキストエリア TAB 機能実装
メンテナンス

非表示 ( No.1 )
日時: 2009/02/21 19:50
名前: lightbox


日時: 2009/02/21 19:50
名前: lightbox
  復帰したい場合または履歴を残したい場合等の削除の代替
拡張子:
	<TD>タイトル</TD>
	<TD>
		<INPUT
			type=text
			name=title
			value="<?= $_POST['title'] ?>"
			style='width:100%'
		>

		<!-- テスト用変更ID -->
		<INPUT type=hidden name=update>
	</TD>
  INPUT 要素でのみ利用できる一般的な隠しフィールド
拡張子:
	<TD>タイトル</TD>
	<TD>
		<INPUT
			type=text
			name=title
			value="<?= $_POST['title'] ?>"
			style='width:100%'
		>

		<!-- テスト用変更ID -->
		<INPUT type=hidden name=update>
	</TD>
  レイアウト的にその要素の存在を全く消してしまいたい時
拡張子:
	<TEXTAREA
		name=board_body
		style='display:none'
	><?= $Column['board_body'] ?></TEXTAREA>
( ※ 戻す場合は、obj.style.display = "" ) レイアウトスペースをそのまま残すのが、style='visibility:hidden' ( ※ 戻す場合は、obj.style.visibility = "visible" ) http://msdn.microsoft.com/en-us/library/ms531180.aspx
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
表示のみのフィールド ( No.2 )
日時: 2007/09/30 13:21
名前: lightbox
  変更できないが、データはサーバーに送る事ができる
拡張子:
	<TD>タイトル</TD>
	<TD>
		<INPUT
			type=text
			name=title
			value="<?= $_POST['title'] ?>"
			readonly
			style='background-color:silver;width:100%'
		>

	</TD>
( ※ 変更不可である事を明示するために、背景色を灰色にしている ) disabled だとサーバーにデータが送られないので注意
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
board.php ( No.3 )
日時: 2018/02/04 19:23
名前: lightbox
拡張子:
<?
require( "model.php" );
# **********************************************************
# 基本定義部分
# **********************************************************
ini_set( 'display_errors', "1" );
$conf_client_charset = "euc-jp";
$conf_db_type = 1;
$conf_db_connect_action = "set names 'ujis'";
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Content-Type: text/html; Charset=$conf_client_charset" );

# **********************************************************
# 外部ファイル
# **********************************************************
inc( "http://lightbox.in.coocan.jp/gen/db.txt" );

# 名前が未入力の場合の表示
$someone = "匿名くん";

# ----------------------------------------------------------
# 通常初期値にクッキーを使用している場合、
# 入力値がある場合は、入力値を使用する
# ----------------------------------------------------------
if ( $_POST['name'] != "" ) {
	$_COOKIE['name'] = $_POST['name'];
}
if ( $_POST['password'] != "" ) {
	$_COOKIE['password'] = $_POST['password'];
}


# **********************************************************
# デバッグ用
# **********************************************************
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
	$ret = print_r($_POST ,true);
}

# **********************************************************
# 接続
# **********************************************************
$SQL = new DB( "localhost", "land", "root", "" );

# **********************************************************
# 更新
# **********************************************************
if ( $_POST['update'] != '' ) {

	$Query = "select * from board ";
	$Query .= " where board_id = '{$_POST['update']}'";
	$Query .= " and board_pass = '" . sha1($_POST['password']) . "'";
	$Column = $SQL->QueryEx( $Query );
	if ( !$Column ) {
		err_msg( "パスワードが一致しません" );
		print "<INPUT type=button value='戻る' onClick='location=\"board.php\"'>";
		exit();
	}

	$Query = "select * from board ";
	$Query .= " where board_body = '{$_POST['body']}'";
	$Query .= " and board_delflg is NULL";
	$Column = $SQL->QueryEx( $Query );
	if ( $Column ) {
		err_msg( "二重投稿です。" );
		print "<INPUT type=button value='戻る' onClick='location=\"board.php\"'>";
		exit();
	}

	$Query = "update board set ";
	$Query .= " board_title = '{$_POST['title']}'";
	$Query .= " ,board_body = '{$_POST['body']}'";
	$Query .= " ,board_update = now()";
	$Query .= " where board_id = {$_POST['update']}";

	$SQL->Execute( $Query );

	ok_msg( "投稿が更新されました" );
	print "<INPUT type=button value='戻る' onClick='location=\"board.php\"'>";
	exit();
}
# **********************************************************
# 削除
# **********************************************************
if ( $_POST['send'] == '削除' ) {

	$Query = "select * from board ";
	$Query .= " where board_id = '{$_POST['board_id']}'";
	$Query .= " and board_pass = '" . sha1($_POST['password']) . "'";
	$Column = $SQL->QueryEx( $Query );
	if ( !$Column ) {
		err_msg( "パスワードが一致しません" );
	}
	else {
		$Query = "update board ";
		$Query .= " set board_delflg = 'D'";
		$Query .= " ,board_update = now()";
		$Query .= " where board_id = {$_POST['board_id']}";
		$ret .= $Query;
		$SQL->Execute( $Query );

	}

	redirect( "board.php" );

	file_put_contents( "debug.log", $ret );

	exit();
}
# **********************************************************
# 新規追加
# **********************************************************
if ( $_POST['send'] != '' ) {

	$err_flg = false;

	$Query = "select * from board ";
	$Query .= " where board_body = '{$_POST['body']}'";
	$Query .= " and board_delflg is NULL";
	$Column = $SQL->QueryEx( $Query );
	if ( $Column ) {
		err_msg( "二重投稿です。" );
		$err_flg = true;
	}

	if ( !$err_flg ) {
		$Query = "select * from access ";
		$Query .= " where access_ip = '{$_SERVER['REMOTE_ADDR']}'";
		$Column = $SQL->QueryEx( $Query );
		if ( $Column ) {
			if ( time() - ($Column['access_time'] + 0) < 10 ) {
				err_msg( "連続投稿です。(しばらくしてから投稿して下さい)" );
				$err_flg = true;
			}
		}
	}

	if ( !$err_flg ) {
		$Query = " insert into board (board_title,board_name,board_pass,board_body,board_create,board_update) ";
		$pass = sha1($_POST['password']);

		if ( trim($_POST['name']) == '' ) {
			$_POST['name'] = $someone;
		}

		$Query .= " values('{$_POST['title']}','{$_POST['name']}','$pass','{$_POST['body']}',now(),now()) ";
		$SQL->Execute( $Query );

		setcookie ("name", $_POST['name'],time()+3600);
		setcookie ("password", $_POST['password'],time()+3600);

		# アクセステーブルの更新
		$tm = time();
		$Query = "update `access` set access_time = $tm where access_ip = '{$_SERVER['REMOTE_ADDR']}'";
		$SQL->Execute( $Query );
		$cnt = mysql_affected_rows( $SQL->Connect );
		if ( $cnt == 0 ) {
			$Query = "insert into access (access_ip,access_time) values('{$_SERVER['REMOTE_ADDR']}',$tm)";
			$SQL->Execute( $Query );
		}

		redirect( "board.php" );

	}
}

# **********************************************************
# 画面定義
# **********************************************************
require( "view.php" );

?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
model.php ( No.4 )
日時: 2007/09/30 13:28
名前: lightbox
拡張子:
<?

# **********************************************************
# URL によるコード取得
# **********************************************************
function inc( $path ) {
	$inc = @file( $path );
	array_shift($inc);
	array_pop($inc);
	$GLOBALS['inc_eval_txt'] = implode( "", $inc );
	eval($GLOBALS['inc_eval_txt']);
}


# **********************************************************
# エラーメッセージ出力
# **********************************************************
function err_msg( $message ) {

	$GLOBALS['ERROR_MSG'] = "<SPAN style='font-weight:bold;font-size:16px;color:red'>$message</SPAN><br><br>";

}

# **********************************************************
# メッセージ出力
# **********************************************************
function ok_msg( $message ) {

	print "<SPAN style='font-weight:bold;font-size:16px;color:blue'>$message</SPAN><br><br>";

}

# **********************************************************
# リダイレクト
# **********************************************************
function redirect( $url ) {

	$str='';
	$str.="<SCRIPT language=\"javascript\" type=\"text/javascript\"> ";
	$str.="\n	window.location = \"$url\"; ";
	$str.="\n</SCRIPT> \n ";
	print $str;

}
?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
view.php ( No.5 )
日時: 2007/09/30 13:29
名前: lightbox
拡張子:
<HTML>
<HEAD>
<!-- *************************************************** -->
<!-- ドキュメント定義部分 -->
<!-- *************************************************** -->
<? require( "view_meta.php" ); ?>
<TITLE>シンプル掲示板</TITLE>
<? require( "view_style.php" ); ?>
<? require( "view_js.php" ); ?>

<!-- *************************************************** -->
<!-- 画面定義部分 -->
<!-- *************************************************** -->
<BODY style='text-align:center'>

<?= $GLOBALS['ERROR_MSG'] ?>

<FORM
	method=post
	onSubmit='return CheckData()'
>

<TABLE id=entry border=1>
<TR>
	<TD>タイトル</TD>
	<TD>
		<INPUT
			type=text
			name=title
			value="<?= $_POST['title'] ?>"
			style='width:100%'
		>

		<!-- テスト用変更ID -->
		<INPUT type=hidden name=update>
	</TD>
</TR>
<TR>
	<TD>名前</TD>
	<TD>
		<INPUT
			type=text
			name=name
			value="<?= $_COOKIE['name'] ?>"
		>

		パスワード
		<INPUT type=password name=password value="<?= $_COOKIE['password'] ?>">
		&nbsp;&nbsp;&nbsp;
		<INPUT
			type=button
			onClick='
				window.open(
					"entry.php",
					null,
					"height=600"+
					",width=600"+
					",status=yes"+
					",toolbar=no"+
					",menubar=no"+
					",location=no"+
					",top=0"+
					",left=0"
				);
			'
			value="別ウインドウで入力"
		>
	</TD>
</TR>
<TR>
	<TD>本文</TD>
	<TD>
		<TEXTAREA
			name=body
			cols=80
			rows=10
		><?= $_POST['body'] ?></TEXTAREA>
	</TD>
</TR>

<TR>
	<TD colspan=2>
		<!-- 変更モードキャンセルボタン -->
		<INPUT
			type=button
			value="リセット"
			onClick='ResetForm()'
			style='float:right;'
		>
		<!-- 通常投稿送信ボタン -->
		<INPUT
			type=submit
			name=send
			value="送信"
		>
	</TD>
</TR>
</TABLE>

</FORM>
<HR>

<?
$Query = "select * from board where board_delflg is NULL order by `board_update` desc";
$Column = $SQL->QueryEx( $Query );

# **********************************************************
# 発言一覧表示部分
# **********************************************************
$row = 1;
print "<TABLE border=0 style='table-layout:fixed;width:80%'>\n";
while( $Column ) {

$Column['board_body'] = htmlspecialchars($Column['board_body']);
$Column['board_title'] = htmlspecialchars($Column['board_title']);
$Column['board_name'] = htmlspecialchars($Column['board_name']);

?>

<TR>
	<TD style='line-height:20px;'>
		【<?= $Column['board_title'] ?>】: <?= $Column['board_create'] ?>
		<br>
		発言者 : <?= $Column['board_name'] ?>
	</TD>
</TR>
<TR>
	<TD valign=top><PRE class=honbun><?= $Column['board_body'] ?></PRE></TD>
</TR>
<TR>
	<TD valign=top>
		<FORM
			method=post
			onSubmit='return CheckDelete( <?= $row ?> )'
		>
			<!-- 削除用送信ボタン -->
			<INPUT
				type=submit
				name=send
				value='削除'
			>
			パスワード
			<INPUT type=password name=password>

			<!-- データ転送用隠しフィールド -->
			<INPUT
				type=hidden
				name=board_id
				value='<?= $Column['board_id'] ?>'
			>
			<INPUT
				type=hidden
				name=board_title
				value='<?= $Column['board_title'] ?>'
			>
			<INPUT
				type=hidden
				name=board_name
				value='<?= $Column['board_name'] ?>'
			>
			<TEXTAREA
				name=board_body
				style='display:none'
			><?= $Column['board_body'] ?></TEXTAREA>

			<!-- 変更データ転送ボタン -->
			<INPUT
				type=button
				value='変更'
				onClick='TransferData( <?= $row ?> )'
			>
		</FORM>
		<br>
	</TD>
</TR>

<?
	$Column = $SQL->QueryEx( );
	$row++;
}
print "</TABLE>\n";

# **********************************************************
# 接続解除
# **********************************************************
$SQL->Close();

?>
<br>
</BODY>
</HTML>

このアーティクルの参照用URLをクリップボードにコピー メンテナンス
SQL文字列中の行コメントを削除する ( No.6 )
日時: 2007/10/03 16:14
名前: lightbox
拡張子:
<?

$txt = '  "aaa" -- ' . "\n";
$txt .= '  "bbb" "ccc" ' . "\n";
$txt .= '  "xxx" -- ' . "\n";

mb_regex_encoding("euc-jp");
$result = mb_ereg_replace( "([^\n-]*)--[^\n]*\n", "\\1\n", $txt );

print "<PRE>";
print $result;
print "</PRE>";

?>
OK
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
さらに、SQL中に PHP の変数を埋め込んでパースする ( No.7 )
日時: 2007/10/03 16:19
名前: lightbox
拡張子:
$result = str_replace('"', '\\"', $result );
eval("\$result = \"$result\";");
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
http://〜 をリンクとして置き換え ( No.8 )
日時: 2007/10/03 16:18
名前: lightbox
拡張子:
$Column['board_body'] = htmlspecialchars($Column['board_body']);

$pattern = "(https?:\/\/[-_.!~*'\(\)a-zA-Z0-9;\/?:\@&=+\$,%#]+)";
$replacement = "<A href=\"\\1\" target=\"_blank\">\\1</A>";
$body_main = mb_ereg_replace( $pattern, $replacement, $Column['board_body'] );

$Column['board_title'] = htmlspecialchars($Column['board_title']);
$Column['board_name'] = htmlspecialchars($Column['board_name']);
$body_main を表示部分に使い、$Column['board_body'] を変更用隠しデータとして使う
このアーティクルの参照用URLをクリップボードにコピー メンテナンス