サインアップ : セッションと関数と雛型


  common.php




共通ファイルですが、ここではシステム全体では無く、このアプリケーションにとっての共通ファイルです。

1) 共通グローバル変数の定義
2) デバッグ用関数の定義


<?php
// セッションを使う時、ソースコードの先頭に
session_start();

// 日本語設定
header( "Content-Type: text/html; Charset=shift_jis" );
// キャッシュを使わない設定
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

$version = "1.001";
$_SESSION['start_php'] = "sign_01.php";
$debug_test = "Y";	// 'Y' でデバッグ実行
check_url();

// *********************************************************
// 部品に直接アクセスした場合のジャンプ
// *********************************************************
function check_url() {

	global $debug_test;

	if ( $debug_test == 'Y' ) {
		return;
	}
	if ( strstr($_SERVER['SCRIPT_NAME'],"sign_") === false ) {
		header("Location: {$_SESSION['start_php']}");
		exit();
	}
}

// *********************************************************
// デバッグ用変数表示関数
// ※ 通常は引数を省略して使用します
// ※ 必要無い場合は、引数に -1 以外をセットします
// ※ $debug_test が 'Y' 以外の場合は常に実行されません
// *********************************************************
function debug_test($type = -1) {

	global $debug_test;

	if ( $debug_test != 'Y' ) {
		return;
	}

	if ( $type === -1 ) {
		// デバッグ用連想配列表示
		print "<hr>";
		print "<pre>";
	
		print "[\$_GET]\n";
		print_r( $_GET );
		print "\n";
	
		print "[\$_POST]\n";
		print_r( $_POST );
		print "\n";
	
		print "[\$_SESSION]\n";
		print_r( $_SESSION );
		print "\n";
	
		print "[グローバル変数]\n";
		// デバッグ用 スーパーグローバル以外のグローバル変数表示
		foreach( $GLOBALS as $Key => $Value  ) {
			if ( strstr( $Key, "_" ) === false ) {
				if ( $Key != 'Key' && $Key != 'Value' && $Key != 'GLOBALS' ) {
					if ( is_array( $Value ) ) {
						print "$Key =>\n";
						print_r($Value);
					}
					else {
						print "$Key => $Value\n";
					}
				}
			}
		}
	
		print "</pre>";
	}

}

?>










  入力、確認、処理終了画面のコントロール




処理としてブラウザとサーバーが会話を行うのに、3種類の画面を用意して、
画面の遷移は、FORM 要素の action 属性を使っています。

sign_01.php : 初期画面を表示するだけ
sign_02.php : 入力値のコントロールをする
sign_03.php : 更新処理をして、処理終了画面を表示する

初期画面は入力フィールドが表示されますが、この初期画面以外にも、入力値を受け取る
sign_02.php でも使用されます。その場合、処理を行うのは sign_02.php ですが、
( つまり、アドレスバーでは sign_02.php と表示されます ) 入力値にエラーが発生した
場合に利用されます。

sign_01.php
  

<?
// 外部  php の読み込み
require_once( "common.php" );
require_once( "model_func.php" );
require_once( "model_01.php" );
require_once( "view_01.php" );

debug_test();
?>
  

sign_02.php
  

<?
// 外部  php の読み込み
require_once( "common.php" );
require_once( "model_func.php" );
require_once( "model_02.php" );
if ( $checkmessge == '' ) {
	require_once( "view_02.php" );
}
else {
	require_once( "view_01.php" );
}

debug_test();
?>
  

sign_03.php
  

<?
// 外部  php の読み込み
require_once( "common.php" );
require_once( "model_func.php" );
require_once( "model_03.php" );
require_once( "view_03.php" );

debug_test();
?>
  





  画面定義

view_01.php
Sign_01

  

<html>
<head>
<!-- 日本語設定 -->
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
</head>
<body>
<? require_once("view_head.php"); ?>
<?
	if ( $checkmessge != '' ) {
		print "<span style='color:#ff0000'>{$checkmessge}</span>";
	}
?>
<!-- データ送信 -->
<form
	name="frm"
	action="sign_02.php"
	target="_self"
	method="get"
	onsubmit='return (function(){return true;})();'
>

<pre>
<!-- データ送信用入力 -->
ユーザーID	<input type="text" name="user_id" value="<?= $_GET['user_id'] ?>">
氏名		<input type="text" name="last_name" value="<?= $_GET['last_name'] ?>">
フリガナ		<input type="text" name="first_name" value="<?= $_GET['first_name'] ?>">
パスワード	<input type="password" name="pass_word" value="<?= $_GET['pass_word'] ?>">

<input type="submit" name="send" value="送信">
</pre>

</form>

</body>
</html>
  

view_02.php
Sign_02

  

<html>
<head>
<!-- 日本語設定 -->
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
</head>
<body>
<? require_once("view_head.php"); ?>

<!-- データ送信 -->
<form
	name="frm"
	action="sign_03.php"
	target="_self"
	method="get"
	onsubmit='return (function(){return true;})();'
>

<pre>
<!-- データ送信用入力 -->
ユーザーID	<?= $_GET['user_id'] ?> 
氏名		<?= $_GET['last_name'] ?> 
フリガナ		<?= $_GET['first_name'] ?> 

<input type="submit" name="send" value="送信">
</pre>

</form>

</body>
</html>
  

view_03.php
Sign_03

  

<html>
<head>
<!-- 日本語設定 -->
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
</head>
<body>
<? require_once("view_head.php"); ?>

<pre>
登録ありがとうございました。

<a href="<?= $_SESSION['start_php'] ?>">最初の画面へ戻る</a>
</pre>

</body>
</html>
  


view_head.php
  

<h3><?= $appname[$_SERVER['SCRIPT_NAME']] ?></h3>
<!-- JavaScript ホームボタン -->
<input
	type="button"
	id="btn"
	value="DIR"
	onclick='location.href="./";'
>

<input
	type="button"
	id="btn"
	value="HOME"
	onclick='location.href="<?= $_SESSION['start_php'] ?>";'
>
<hr>
  




  それぞれの画面の処理

model_01.php
  

<?
$app = $_SERVER['SCRIPT_NAME'];
$appname[$app] = "入力画面";

?>
  

model_02.php
  

<?
$app = $_SERVER['SCRIPT_NAME'];
$appname[$app] = "確認画面";

// エラーチェックの呼び出し
$checkmessge = "";
entry_check($checkmessge);

?>
  

model_03.php
  

<?
$app = $_SERVER['SCRIPT_NAME'];
$appname[$app] = "処理終了画面";

// 更新処理の呼び出し
entry_update();

?>
  


model_func.php
  

<?
// *********************************************************
// 入力チェツク
// 
// 引数に「参照」を使用して、グローバルでメッセージを使える
// ようにしています。
// *********************************************************
function entry_check( &$checkmessge ) {

	if ( trim($_GET[user_id]) == '' ) {
		$checkmessge = 'ユーザーid を入力して下さい';
		return;
	}

	$_SESSION['user_id'] = $_GET['user_id'];
	$_SESSION['last_name'] = $_GET['last_name'];
	$_SESSION['first_name'] = $_GET['first_name'];
	$_SESSION['pass_word'] = $_GET['pass_word'];

}


// *********************************************************
// 更新処理の補助
// *********************************************************
function entry_add( &$str, $var_name ) {

	$str .= $_SESSION[$var_name] . "\n";

}

// *********************************************************
// 更新処理
// *********************************************************
function entry_update() {

	$file_name = uniqid();
	$file_text = "";

	entry_add( $file_text, "user_id" );
	entry_add( $file_text, "last_name" );
	entry_add( $file_text, "first_name" );
	entry_add( $file_text, "pass_word" );

	file_put_contents( $file_name . ".txt", $file_text );

}

?>
  








yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[webclass]
CCBot/2.0 (https://commoncrawl.org/faq/)
23/12/09 07:53:53
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube