簡易標準化ファイル

  PHP用簡易標準化ファイル( common.php )



コードとしては古いですが、過去ずっと使ってるのでキャッシュはいつも過去日付でやってます。
昔 IE4.0 の時、IE がバグっていて、特別な方法が動作しなかったという痛い経験があるので、変えれないです。

最近は、SQLインジェクションとか言われていますが、専門家が少しその気になって考えて、
そのプロジェクトで標準化すれば実用では問題無いので、末端のプログラマが考える事ではありません。

ただ、実際問題として、WEBプログラミングは誰でもできてしまうので、一般の人が作った
ものが問題になっているだけだと理解しています。勉強している段階では、目の前の「動かない」
を回避するほうが先決です。じっくりやって追いつけるほどこの世界は優しく無いですから。

  
<?
header( "Content-Type: text/html; Charset=shift_jis" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

foreach( $_GET as $Key => $Value ) {
	$_POST[$Key] = $_GET[$Key];
}
foreach( $_POST as $Key => $Value ) {
	$_POST[$Key] = str_replace("\\\\", "\\", $Value );
	$_POST[$Key] = str_replace("\\'", "'", $_POST[$Key] );
	$_POST[$Key] = str_replace("\\\"", "\"", $_POST[$Key] );
}

# **********************************************************
# 環境
# **********************************************************
define( 'COMMON_AUTHOR', 'LIGHTBOX' );
$COMMON_VERSION = '6.0410';


# **********************************************************
# ダブルクォート表示用処理
# **********************************************************
function RestoreValue( ) {

	foreach( $_POST as $Key => $Value ) {
		$_POST[$Key] = str_replace("\"", """, $_POST[$Key] );
	}

}

# **********************************************************
# クッキーデータの復帰
# **********************************************************
function RestoreCookie( ) {

	foreach( $_COOKIE as $Key => $Value ) {
		if ( substr( $Key, 0, 2 ) == 'In' ) {
			if ( !isset( $_POST[$Key] ) ) {
				$_POST[$Key]
				 = str_replace("\\\\", "\\", $_COOKIE[$Key] );
				$_POST[$Key]
				 = str_replace("\\'", "'", $_POST[$Key] );
				$_POST[$Key]
				 = str_replace("\\\"", "\"", $_POST[$Key] );
			}
		}
	}

}

# **********************************************************
# エラーメッセージのセット
# **********************************************************
function SetError( $Message ) {

	$GLOBALS['ErrMessage'] = $Message;

}

# **********************************************************
# 引継ぎ用埋め込みデータの作成
# **********************************************************
function CreateInData( ) {

	global $InData;

	$InData = "";

	foreach( $_POST as $Key => $Value ) {
		if ( substr( $Key, 0, 2 ) == "In" ) {
			if ( substr( $Key, 0, 3 ) != "In2" ) {
				$InData .= "<INPUT type=hidden name=$Key ";
				$InData .= "value=\"$Value\">\n";
			}
		}
	}

}

# **********************************************************
# オプション文字列の作成
# **********************************************************
function CreateOption( &$SQL, $FieldName, $Query ) {

	$Column = $SQL->QueryEx( $Query );

	$Ret = "";
	while ( $Column ) {
		$Ret .= "<OPTION value={$Column[0]}";
		if ( $Column[0] == $_POST[$FieldName] ) {
			$Ret .= " selected";
		}
		$Ret .= ">{$Column[1]}</OPTION>\n";
		$Column = $SQL->QueryEx( );
	}

	return $Ret;

}

# **********************************************************
# リダイレクト
# **********************************************************
function Redirect( $Target ) {

	header( "Location: $Target" );

}

# **********************************************************
# 挟み込み関数
# **********************************************************
function Enclose( $strValue, $Chr, $Type, $Option="" ) {

	$strRet = "";

	switch( $Type ) {
		# 単純挟み込み
		case 0:
			$strRet = $Chr . $strValue . $Chr;
			break;
		# HTML挟み込み
		case 1:
			$strRet = "<" . $Chr . " " . $Option . ">";
			$strRet .= $strValue;
			$strRet .= "</" . $Chr . ">";
			break;
	}

	return $strRet;

}

# **********************************************************
# ' 挟み込み関数
# **********************************************************
function Ss( $strValue ) {

	return Enclose( $strValue, "'", 0 );

}

# **********************************************************
# " 挟み込み関数
# **********************************************************
function Dd( $strValue ) {

	return Enclose( $strValue, "\"", 0 );

}

# **********************************************************
# 改行付表示関数
# **********************************************************
function OutCr( $strValue ) {

	print $strValue . "\n";

}

# **********************************************************
# デバッグ用情報表示関数
# **********************************************************
function DispHash( &$Hash, $strTitle="" ) {

	$Option = "bgcolor=white";

	OutCr( "<TABLE border=0 bgcolor=black cellspacing=1>" );
	OutCr( Th( "$strTitle 名称", "bgcolor=silver" ) );
	OutCr( Th( 内容, "bgcolor=silver" ) );
	foreach( $Hash as $Key => $Value ) {
		OutCr( "<TR>" );
		OutCr( Td( $Key, $Option ) );
		OutCr( Td( $Value, $Option ) );
		OutCr( "</TR>" );
	}
	OutCr( "</TABLE>" );

}

# **********************************************************
# デバッグ用情報表示関数
# **********************************************************
function DispDebug( $strType="MISS" ) {

	$TableTag = "<TABLE border=0 bgcolor=black cellspacing=1>";
	$Err = "デバッグ用情報表示関数への引数が誤っています";
	$Option = "bgcolor=white";

	switch( $strType ) {
		case "VER":
			OutCr( $TableTag );
			OutCr( Th( "現在のPHPバージョン", "bgcolor=silver" ) );
			OutCr( "<TR>" );
			OutCr( Td( phpversion(), $Option ) );
			OutCr( "</TR>" );
			OutCr( "</TABLE>" );
			break;

		case "POST":
			DispHash( $_POST, "POST" );
			break;

		case "GET":
			DispHash( $_GET, "GET" );
			break;

		case "SESSION":
			if ( isset( $_SESSION ) ) {
				DispHash( $_SESSION, "SESSION" );
			}
			break;

		case "ENV":
			DispHash( $_ENV, "ENV" );
			break;

		case "SERVER":
			DispHash( $_SERVER, "SERVER" );
			break;

		case "COOKIE":
			DispHash( $_COOKIE, "COOKIE" );
			break;

		case "REQUEST":
			DispHash( $_REQUEST, "REQUEST" );
			break;

		default:
			OutCr( $TableTag );
			OutCr( Th( $Err, $Option ) );
			OutCr( "</TABLE>" );
			break;
	}

}

# **********************************************************
# <TH> 挟み込み関数
# **********************************************************
function Th( $strValue, $Option="" ) {

	return Enclose( $strValue, "TH", 1, $Option );

}

# **********************************************************
# <TD> 挟み込み関数
# **********************************************************
function Td( $strValue, $Option="" ) {

	return Enclose( $strValue, "TD", 1, $Option );

}

# **********************************************************
# デバッグ用メッセージの表示 (1)
# **********************************************************
function DispData() {

	DispHash( $_GET, "GET" );
	DispHash( $_POST, "POST" );
	DispHash( $_COOKIE, "COOKIE" );
	if ( isset( $_SESSION ) ) {
		DispHash( $_SESSION, "SESSION" );
	}

}

# **********************************************************
# デバッグ用メッセージの表示 (2)
# **********************************************************
function DispArray( &$Array ) {

	OutCr( "<PRE>" );
	print_r( $Array );
	OutCr( "</PRE>" );

}

# **********************************************************
# デバッグ用メッセージの表示 (3)
# **********************************************************
function DispDump( &$Var ) {

	var_dump( $Var );

}

# **********************************************************
# DTPicker の value 属性用の値の取得
# 9999/99/99 ????? または 9999-99-99 ?????
# という入力文字列を処理する
# それ以外の文字列が渡されると当日の文字列を使用する
# (時間は切り捨てる)
# **********************************************************
function GetDtpValue( $strDate ) {

	$Base = gregoriantojd(12,30,1899);
	$Target = gregoriantojd(Date("n"),Date("j"),Date("Y"));
	$strDelim = "\0";

	if ( FALSE !== strpos( $strDate, "/" ) ) {
		$strDelim = "/";
	}
	if ( FALSE !== strpos( $strDate, "-" ) ) {
		$strDelim = "-";
	}
	$DatePart = explode( $strDelim, $strDate );
	if ( is_array( $DatePart ) ) {
		$Cnt = count( $DatePart );
		if ( $Cnt >= 3 ) {
			if ( $DatePart[0] < 50 ) {
				$DatePart[0] += 2000;
			}
			if ( $DatePart[0] < 100 ) {
				$DatePart[0] += 1900;
			}
			$DatePart2 = explode( " ", $DatePart[2] );
			$Target = gregoriantojd(
				$DatePart[1],
				$DatePart2[0],
				$DatePart[0]
			);
		}
	}
	return( $Target - $Base );

}
# **********************************************************
# DTPicker が POST した 月/日/年 を 年/月/日 に変換する
# (時間は切り捨てる)
# **********************************************************
function GetDtpPostValue( $strDate ) {

	$strDelim = "";

	if ( FALSE !== strpos( $strDate, "/" ) ) {
		$strDelim = "/";
	}
	if ( FALSE !== strpos( $strDate, "-" ) ) {
		$strDelim = "-";
	}
	$DatePart = explode( $strDelim, $strDate );
	$DatePart2 = explode( " ", $DatePart[2] );
	if ( $DatePart2[0] < 50 ) {
		$DatePart2[0] += 2000;
	}
	if ( $DatePart2[0] < 100 ) {
		$DatePart2[0] += 1900;
	}
	return $DatePart2[0] . "/" . $DatePart[0] . "/" . $DatePart[1];

}

?>
  



  旧 common.php



  
<?
header( "Content-Type: text/html; Charset=shift_jis" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

foreach( $_GET as $Key => $Value ) {
	$_POST[$Key] = $_GET[$Key];
}
foreach( $_POST as $Key => $Value ) {
	$_POST[$Key] = str_replace("\\\\", "\\", $Value );
	$_POST[$Key] = str_replace("\\'", "'", $_POST[$Key] );
	$_POST[$Key] = str_replace("\\\"", "\"", $_POST[$Key] );
}

# **********************************************************
# 環境
# **********************************************************
define( 'COMMON_AUTHOR', 'LIGHTBOX' );
$COMMON_VERSION = '3.0628';

# **********************************************************
# DTPicker の value 属性用の値の取得
# 9999/99/99 ????? または 9999-99-99 ?????
# という入力文字列を処理する
# それ以外の文字列が渡されると当日の文字列を使用する
# (時間は切り捨てる)
# **********************************************************
function GetDtpValue( $strDate ) {

	$Base = gregoriantojd(12,30,1899);
	$Target = gregoriantojd(Date("n"),Date("j"),Date("Y"));
	$strDelim = "\0";

	if ( FALSE !== strpos( $strDate, "/" ) ) {
		$strDelim = "/";
	}
	if ( FALSE !== strpos( $strDate, "-" ) ) {
		$strDelim = "-";
	}
	$DatePart = explode( $strDelim, $strDate );
	if ( is_array( $DatePart ) ) {
		$Cnt = count( $DatePart );
		if ( $Cnt >= 3 ) {
			if ( $DatePart[0] < 50 ) {
				$DatePart[0] += 2000;
			}
			if ( $DatePart[0] < 100 ) {
				$DatePart[0] += 1900;
			}
			$DatePart2 = explode( " ", $DatePart[2] );
			$Target = gregoriantojd(
				$DatePart[1],
				$DatePart2[0],
				$DatePart[0]
			);
		}
	}
	return( $Target - $Base );

}
# **********************************************************
# DTPicker が POST した 月/日/年 を 年/月/日 に変換する
# (時間は切り捨てる)
# **********************************************************
function GetDtpPostValue( $strDate ) {

	$strDelim = "";

	if ( FALSE !== strpos( $strDate, "/" ) ) {
		$strDelim = "/";
	}
	if ( FALSE !== strpos( $strDate, "-" ) ) {
		$strDelim = "-";
	}
	$DatePart = explode( $strDelim, $strDate );
	$DatePart2 = explode( " ", $DatePart[2] );
	if ( $DatePart2[0] < 50 ) {
		$DatePart2[0] += 2000;
	}
	if ( $DatePart2[0] < 100 ) {
		$DatePart2[0] += 1900;
	}
	return $DatePart2[0] . "/" . $DatePart[0] . "/" . $DatePart[1];

}

# **********************************************************
# クッキーデータの復帰
# **********************************************************
function RestoreCookie( ) {

	foreach( $_COOKIE as $Key => $Value ) {
		if ( substr( $Key, 0, 2 ) == 'In' ) {
			if ( !isset( $_POST[$Key] ) ) {
				$_POST[$Key]
				 = str_replace("\\\\", "\\", $_COOKIE[$Key] );
			}
		}
	}

}

# **********************************************************
# エラーメッセージのセット
# **********************************************************
function SetError( $Message ) {

	$GLOBALS['ErrMessage'] = $Message;

}

# **********************************************************
# 引継ぎ用埋め込みデータの作成
# **********************************************************
function CreateInData( ) {

	global $InData;

	$InData = "";

	foreach( $_POST as $Key => $Value ) {
		if ( substr( $Key, 0, 2 ) == "In" ) {
			if ( substr( $Key, 0, 3 ) != "In2" ) {
				$InData .= "<INPUT type=hidden name=$Key ";
				$InData .= "value=\"$Value\">\n";
			}
		}
	}

}

# **********************************************************
# オプション文字列の作成
# **********************************************************
function CreateOption( &$SQL, $FieldName, $Query ) {

	$Column = $SQL->QueryEx( $Query );

	$Ret = "";
	while ( $Column ) {
		$Ret .= "<OPTION value={$Column[0]}";
		if ( $Column[0] == $_POST[$FieldName] ) {
			$Ret .= " selected";
		}
		$Ret .= ">{$Column[1]}</OPTION>\n";
		$Column = $SQL->QueryEx( );
	}

	return $Ret;

}

# **********************************************************
# リダイレクト
# **********************************************************
function Redirect( $Target ) {

	header( "Location: $Target" );

}

# **********************************************************
# キャラクタセットを指定するMETAタグ文字列作成関数
# **********************************************************
function MetaCharset( $Target ) {

	$strRet = '<META';
	$strRet .= ' http-equiv="Content-type"';
	$strRet .= " content=\"text/html; charset=$Target\">";

	return $strRet;

}

# **********************************************************
# 挟み込み関数
# **********************************************************
function Enclose( $strValue, $Chr, $Type, $Option="" ) {

	$strRet = "";

	switch( $Type ) {
		# 単純挟み込み
		case 0:
			$strRet = $Chr . $strValue . $Chr;
			break;
		# HTML挟み込み
		case 1:
			$strRet = "<" . $Chr . " " . $Option . ">";
			$strRet .= $strValue;
			$strRet .= "</" . $Chr . ">";
			break;
	}

	return $strRet;

}

# **********************************************************
# ' 挟み込み関数
# **********************************************************
function Ss( $strValue ) {

	return Enclose( $strValue, "'", 0 );

}

# **********************************************************
# " 挟み込み関数
# **********************************************************
function Dd( $strValue ) {

	return Enclose( $strValue, "\"", 0 );

}

# **********************************************************
# <TH> 挟み込み関数
# **********************************************************
function Th( $strValue, $Option="" ) {

	return Enclose( $strValue, "TH", 1, $Option );

}

# **********************************************************
# <TD> 挟み込み関数
# **********************************************************
function Td( $strValue, $Option="" ) {

	return Enclose( $strValue, "TD", 1, $Option );

}

# **********************************************************
# <A href> 挟み込み関数
# **********************************************************
function Alink( $Url, $strValue, $Option="" ) {

	return Enclose( $strValue, "A", 1, "href=" . Dd($Url) . " " . $Option );

}

# **********************************************************
# <DIV> 挟み込み関数
# **********************************************************
function Div( $strValue, $Option="" ) {

	return Enclose( $strValue, "DIV", 1, $Option );

}

# **********************************************************
# 改行付表示関数
# **********************************************************
function OutCr( $strValue ) {

	print $strValue . "\n";

}

# **********************************************************
# タイトル表示関数
# **********************************************************
function DispTitle( $strTitle ) {

	$strValue = Div( $strTitle, "style='margin-top:5'" );
	$strValue = Div( $strValue, "class=SYSTEM_TITLE" );

	OutCr( $strValue );

}

# **********************************************************
# ウインドウ最大化JavaScript出力関数
# **********************************************************
function MaxWindow( ) {

	OutCr( '<!-- ' . str_repeat("*", 75) );
	OutCr( ' ページロード時の初期処理' );
	OutCr( str_repeat("*", 76) . ' -->' );
	OutCr( '<SCRIPT FOR=window EVENT=onload LANGUAGE=JavaScript>' );
	OutCr( '' );
	OutCr( '	window.focus();' );
	OutCr( '	top.moveTo( 0, 0 );' );
	OutCr( '	top.resizeTo( screen.width, screen.height - 32 );' );
	OutCr( '' );
	OutCr( '</SCRIPT>' );

}

# **********************************************************
# デバッグ用情報表示関数
# **********************************************************
function DispHash( &$Hash, $strTitle="" ) {

	$Option = "bgcolor=white";

	OutCr( "<TABLE border=0 bgcolor=black cellspacing=1>" );
	OutCr( Th( "$strTitle 名称", "bgcolor=silver" ) );
	OutCr( Th( 内容, "bgcolor=silver" ) );
	foreach( $Hash as $Key => $Value ) {
		OutCr( "<TR>" );
		OutCr( Td( $Key, $Option ) );
		OutCr( Td( $Value, $Option ) );
		OutCr( "</TR>" );
	}
	OutCr( "</TABLE>" );

}

# **********************************************************
# デバッグ用情報表示関数
# **********************************************************
function DispDebug( $strType="MISS" ) {

	$TableTag = "<TABLE border=0 bgcolor=black cellspacing=1>";
	$Err = "デバッグ用情報表示関数への引数が誤っています";
	$Option = "bgcolor=white";

	switch( $strType ) {
		case "VER":
			OutCr( $TableTag );
			OutCr( Th( "現在のPHPバージョン", "bgcolor=silver" ) );
			OutCr( "<TR>" );
			OutCr( Td( phpversion(), $Option ) );
			OutCr( "</TR>" );
			OutCr( "</TABLE>" );
			break;

		case "POST":
			DispHash( $_POST, "POST" );
			break;

		case "GET":
			DispHash( $_GET, "GET" );
			break;

		case "SESSION":
			if ( isset( $_SESSION ) ) {
				DispHash( $_SESSION, "SESSION" );
			}
			break;

		case "ENV":
			DispHash( $_ENV, "ENV" );
			break;

		case "SERVER":
			DispHash( $_SERVER, "SERVER" );
			break;

		case "COOKIE":
			DispHash( $_COOKIE, "COOKIE" );
			break;

		case "REQUEST":
			DispHash( $_REQUEST, "REQUEST" );
			break;

		default:
			OutCr( $TableTag );
			OutCr( Th( $Err, $Option ) );
			OutCr( "</TABLE>" );
			break;
	}

}

# **********************************************************
# デバッグ用メッセージの表示
# **********************************************************
function DispData() {

	DispHash( $_GET, "GET" );
	DispHash( $_POST, "POST" );
	DispHash( $_COOKIE, "COOKIE" );
	if ( isset( $_SESSION ) ) {
		DispHash( $_SESSION, "SESSION" );
	}

}

# **********************************************************
# デバッグ用メッセージの表示
# **********************************************************
function DispArray( &$Array ) {

	OutCr( "<PRE>" );
	print_r( $Array );
	OutCr( "</PRE>" );

}
?>
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ