<?php
//========================================================//
//■メイン
//
//========================================================//
//ファイル読み込み
require_once("./init.php");
$h = new html();
$sql = new sql_init();
$h->header_html("新規登録");//ヘッダー
//質問の内容
$ques = array(
'1'=>'あなたの好きな食べ物は?',
'2'=>'あなたの好きな曲は?',
'3'=>'あなたの母親の旧姓は?',
'4'=>'あなたの好きな映画は?',
);
$ch = new Check();
if($_SERVER['REQUEST_METHOD'] == "GET"){
$_POST['mode'] = &$_GET['mode'];
}
switch($_POST['mode']):
case 'write': // チェック処理へ;
$ch->user_form_check();
break;
case 'ok': // 登録処理へ;
$ch->torokuok();
break;
case 'he': //確認画面から編集画面へ
$ch->user_sinki_form();
break;
default:
$ch->user_sinki_form();
break;
endswitch;
exit();
class Check{
//===========================================================================================
//新規登録フォーム
//===========================================================================================
function user_sinki_form($userID_error ="",$pass_error ="",$passk_error
="",$mail_error ="",$kota_error ="",$userID = "",$mail = "",$himi ="",$kota
="",$error_flg =""){
if($error_flg != true){
$userID = $_POST['userID'];//ユーザID
$mail = $_POST['mail'];//メールアドレス
$himi = $_POST['himi'];//秘密の質問
$kota = $_POST['kota'];//秘密の質問の答え
}
//秘密の質問フォーム生成
$select = $this->ques_form($himi);
echo <<<EOM
<table width="600px">
<h2 class="black">ユーザー登録</h2>
ようこそ、ノブログへ。ユーザー登録をすれば、
<a
href="/kari.htm">ノブログの様々なサービス</a>
をご利用いただけます。<br>
<div
class="black"><strong>ユーザー登録は無料</strong>です。
以下の項目に間違いがないよう入力してください。</div>
<br>
</td></tr>
</table>
<span class="bord-o">
<table class="orange" border="0" width="600px">
<form action="sinki_add.php" method="post">
<input type="hidden" name="mode" value="write">
<tr>
<th valign="top">
ユーザーID
</th>
<td>
<span class="red">$userID_error</span>
<strong>http://www.noblog
<input type="text" name="userID" maxlength="20" size="25"
style="ime-mode: disabled;" value="$userID">
.co.jp/</strong>
<br>(例:suzuki-2006)
<br>※英字で始まり英字か数字で終わる<br>
<strong>4文字から20文字以内のハイフン(-)を含む半角小文字の英数字</strong>
</td>
</tr>
<tr>
<th valign="top">
パスワード
</th>
<td>
<span class="red">$pass_error</span><input type="password"
name="passwd" maxlength="16" size="25" style="ime-mode:
disabled;"><br>
※4文字以上、16文字以内の半角英数字
</td>
</tr>
<tr>
<th valign="top">
パスワードの確認
</th>
<td>
<span class="red"> $passk_error</span><input type="password"
name="passwd_r" maxlength="16" size="25" style="ime-mode:
disabled;"><br><br>
</td>
</tr>
<tr>
<th valign="top">
メールアドレス<br>
[非公開]
</th>
<td>
<span class="red">$mail_error</span><input type="text"
name="mail" maxlength="100" size="50" style="ime-mode: disabled;"
value="$mail"><br>
(例:nobulog@example.com)
<br>※携帯電話のメールアドレスは登録できません
<br><br>
</td>
</tr>
<tr>
<th valign="top"> 秘密の質問<br>
<td>
質問
EOM;
//秘密の質問表示(implode:配列を文字列で表示)
echo implode("\n",$select);
echo <<<EOM
<br><span class="red">$kota_error</span>
答え
<input type="text" name="kota" maxlength="15" size="30"
value="$kota">*パスワードを忘れてしまったときに必要<br>
</td>
</tr>
</table>
</span>
<table width="600px">
<tr><td>
<a
href="../riyou.html">利用規約</a>を読み、同意した上で確認ボタンを押してください。
<input type="submit" value="確認画面へ">
</tr></td>
</table>
<!--リンク-->
<table width="600px">
<tr><td>
<br><br><div class="hr2"></div>
</td></tr>
<tr><td>
<a href="../policy.html">プライバシーポリシー</a>
</tr></td>
<tr><td>
<a href="../company.html">会社概要</a>
</td></tr>
<tr><td>
<a href="../otoiawase.html">お問い合わせ</a>
</td></tr>
<tr><td>
<a href="../index.html">トップ</a>
</td></tr>
</table>
</div>
</div>
EOM;
}
//==================================================================================
//質問内容格納処理
//==================================================================================
function ques_form($himi){
global $ques; //グローバルとして読み込む
//初期化
$select = array("<select name=\"himi\">");
//格納処理
foreach($ques as $key => $value) {
//初期値決定
if($himi == $key){
//一致したやつにチェック
$selected="selected";
}else{
//なかった
$selected="";
}
//格納
array_push($select,"<option
value=\"$key\"$selected>$value</option>");
}
//最後は閉じる
array_push($select,"</select>");
//配列返す
return $select;
}
//==================================================================================
//エラーチェック
//==================================================================================
function user_form_check(){
//フラグの初期値設定
$error_flg = false;
//入力された値を入れる
$userID = $_POST['userID'];//ユーザID
$passwd = $_POST['passwd'];//パスワード
$passwd_r = $_POST['passwd_r'];//パスワード確認
$mail = $_POST['mail'];//メールアドレス
$himi = $_POST['himi'];//秘密の質問
$kota = $_POST['kota'];//秘密の質問の答え
//パスワードの文字数を取得
$c = strlen($passwd);
$userID = strtolower("$userID");
if(!isset($userID) || $userID ==""){
//ユーザIDに値が入っているかチェック
$userID_error = "ユーザーIDを入力してください</br>";
//エラーフラグ
$error_flg = true;
}elseif(strlen($userID) < 4 ||
!ereg("^[a-z]+[a-z0-9\-]*[a-z0-9]$",$userID)){
//ユーザIDの文字数と型式チェック
$userID_error
="ユーザIDは半角英数字4文字から20文字の範囲で入力してください</br>";
$error_flg = true;
}elseif($this->id_check($userID) == true){
$userID_error =
"そのIDはすでに使われています</br>";
$error_flg = true;
}
if(!isset($passwd) || $passwd ==""){
//パスワードに値が入っているかチェック
$pass_error = "パスワードを入力してください</br>";
$error_flg = true;
}elseif($c < 4 || !ereg("^[a-z0-9]",$passwd)){
//パスワードの文字数と型式チェック
$pass_error =
"パスワードは半角英数字4文字以上16字以内の範囲で入力してください</br>";
$error_flg = true;
}elseif(!isset($passwd_r) || $passwd_r ==""){
//パスワード確認のチェック
$passk_error =
"パスワード確認を入力してください</br>";
$error_flg = true;
}elseif($passwd !== $passwd_r){
//パスワードが確認と一致するかチェック
$passk_error =
"パスワードが確認と一致しません</br>";
$error_flg = true;
}
if(!isset($mail) || $mail ==""){
//メールアドレスのチェック
$mail_error
="メールアドレスを入力してください</br>";
$error_flg = true;
}elseif(!ereg("^[a-zA-Z0-9_\.\-]+@(([a-zA-Z0-9_\-]+\.)+[a-zA-Z0-9]+$)",$mail)){
//メールアドレスの構文チェック
$mail_error
="メールアドレスが正しくありません</br>";
$error_flg = true;
}elseif($this->mail_check($mail) == true){
$mail_error
="そのメールアドレスはすでに登録されています</br>";
$error_flg = true;
}
if(!isset($kota) || $kota ==""){
//答えが入力されているかチェック
$kota_error = "答えを入力してください</br>";
$error_flg = true;
}
if($error_flg == true){
//新規登録フォームに戻りエラーを表示
$this->user_sinki_form($userID_error,$pass_error,$passk_error,$mail_error,$kota_error,$userID,$mail,$himi,$kota);
}else{
//確認画面にとぶ
$this->user_kakunin($userID,$passwd,$passwd_r,$mail,$himi,$kota,$c);
}
}
//==================================================================================
//IDの重複チェック
//==================================================================================
function id_check($userID){
//Mysqlへ接続
$con_id = sql_init::connect();
//ユーザID照合
global $usr;
$sql = "select {$usr['id']} from {$usr['colum']} where {$usr['id']} =
'$userID'";
$res = mysql_query($sql,$con_id);
$rows = mysql_num_rows($res);
//重複するIDがあるかどうかの判定
if($rows != 0)
{
$id_flg = true;
}else{
$id_flg = false;
}
return $id_flg;
}
//==================================================================================
//メールアドレスの重複チェック
//==================================================================================
function mail_check($mail){
//Mysqlへ接続
$con_id = sql_init::connect();
//メールアドレス照合
global $usr;
$sql = "select {$usr['mail']} from {$usr['colum']} where {$usr['mail']} =
'$mail'";
$res = mysql_query($sql,$con_id);
$rows = mysql_num_rows($res);
//重複するメールアドレスがあるかどうかの判定
if($rows != 0)
{
$mail_flg = true;
}else{
$mail_flg = false;
}
return $mail_flg;
}
//=====================================================================================
//確認画面
//=====================================================================================
function user_kakunin($userID,$passwd,$passwd_r,$mail,$himi,$kota,$c){
global $ques;
//秘密の質問、プルダウンで選ばれたものを表示するための処理
foreach($ques as $key => $value) {
if($himi == $key){
//一致したやついれる
$situmon=$value;
break;
}
}
//パスワードを*に変換する処理
while ($c > 0){
//文字数分*を出力
$passh .= "*";
$c--;
}
//=====================================================================================
//確認画面表示
//=====================================================================================
echo <<<EOM
<table width="600px">
<h2 class="black">確認画面</h2>
<div
class="black"><strong>以下の内容でよろしいですか?</strong></div>
<br>
</td></tr>
</table>
<span class="bord-o">
<table class="orange" border="0" width="600px">
<tr>
<th valign="top">
ユーザーID
</th>
<td>
<strong>$userID
</td>
</tr>
<tr>
<th>
パスワード
</th>
<td>
$passh
</td>
</tr>
<tr>
<th>
メールアドレス<br>
</th>
<td>
$mail
</td>
</tr>
<tr>
<th valign="top">
秘密の質問
</th>
<td>
質問:$situmon<br>
答え:$kota
</td>
</tr>
</table>
</span>
<table width="600px">
<tr>
<td>修正する箇所がある方は、修正ボタンを押してください
<form action="sinki_add.php" name="mode" method="post">
<input type="hidden" name="mode" value="he">
<input type="hidden" name="userID" value="$userID">
<input type="hidden" name="mail" value="$mail">
<input type="hidden" name="himi" value="$himi">
<input type="hidden" name="kota" value="$kota">
<INPUT type="submit"
value="登録内容を修正する"><br><br>
</form></td>
</tr>
<tr>
<td>良い場合は登録ボタンを押してください
<form action="sinki_add.php" name="mode" method="post">
<input type="hidden" name="mode" value="ok">
<input type="hidden" name="userID" value="$userID">
<input type="hidden" name="passwd" value="$passwd">
<input type="hidden" name="mail" value="$mail">
<input type="hidden" name="himi" value="$himi">
<input type="hidden" name="kota" value="$kota">
<input type="submit" name="ok" value="同意して登録する">
</form></td>
</tr>
</table>
</div>
</div>
EOM;
}
//================================================================================
//仮登録完了画面
//================================================================================
function torokuok(){
$userID = $_POST['userID'];//ユーザID
$passwd = $_POST['passwd'];//パスワード
$mail = $_POST['mail']; //メールアドレス
$himi = $_POST['himi']; //秘密の質問
$kota = $_POST['kota']; //秘密の質問の答え
$karidate = date(Ymd); //仮登録日
//===============================================================================
//認証キーを作成
//===============================================================================
do{
$ninkey = ""; //認証キー
$len = 10; //長さ
$kosuu = 0; //使用文字個数初期化
$hani = 61; //使用文字範囲初期化
//数字
foreach (range('0', '9') as $num){
$array[$kosuu] = $num;
$kosuu++;
}
//アルファベット(小文字)
foreach (range('a', 'z') as $num){
$array[$kosuu] = $num;
$kosuu++;
}
//アルファベット(大文字)
foreach (range('A', 'Z') as $num){
$array[$kosuu] = $num;
$kosuu++;
}
//生成
for($i = 0;$i <= $len; $i++){
$ninkey .= $array[rand(0 ,$hani)];
}
}while($ninkey == "FFFFFFFF");
//==============================================================================
//入力した内容とかをデータベースに登録(ユーザテーブル)
//==============================================================================
//Mysqlへ接続
$con_id = sql_init::connect();
global $usr;
$sql = "INSERT INTO {$usr['colum']}
VALUES('$userID','$passwd','$mail','$himi','$kota','$ninkey','$karidate')";
//SQL文送信
$res = mysql_query($sql,$con_id);
//メール送信へ
$this->mailso($userID,$mail,$ninkey);
//=============================================================================
//仮登録完了画面表示
//=============================================================================
echo <<<EOM
<div class="gradation2">
<div class="gra-box2">
仮登録の完了
</div>
<br>
<br>
<table>
<tr>
<td>
仮登録が完了しました<br>
メールに書いてあるURLをクリックすると本登録の画面に進みます<br><br>
</td>
</tr>
</table>
<br><br><br><br><br><br>
</div>
</div>
</div>
EOM;
}
//============================================================================
//メール送信
//============================================================================
function mailso($userID,$mail,$ninkey){
//↓送信内容
$msg = "
仮登録ありがとうございます\n
$userID\n
認証キー: $ninkey\n";
mb_language("Ja");
mb_internal_encoding("EUC-JP");
$mailto="$mail";//送信先
$subject="タイトル";//タイトル
$content="$msg";//内容
$mailfrom="From:" .mb_encode_mimeheader("ノブログ運営局") ."noblog@aaa.com";
mb_send_mail($mailto,$subject,$content,$mailfrom);//メール送信
}
}
?>