<form>
<fieldset><legend>註冊 (申請) 帳號</legend>
<ol>
<li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds"></li>
<li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合"></li>
<li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"></li>
<li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option></select></li>
<li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option></select></li>
<li><button type="submit">建立</button></li>
</ol>
</fieldset>
</form>
善用 html 5 填表元素新屬性
<form>
<fieldset><legend>註冊 (申請) 帳號</legend>
<ol>
<li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds" title="有效的電子信箱,如 thanks@lots.friends" required autofocus autocomplete="off"></li>
<li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合" title="密碼:大小寫英文字母及數字混合,6~18字,如 A12Rd6" minlength="6" required pattern="(?=^[A-Za-z0-9]{6,18}$)((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]))^.*$"></li>
<li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30" autocomplete="off"></li>
<li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option></select></li>
<li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option></select></li>
<li><button type="submit">建立</button></li>
</ol>
</fieldset>
</form>
①district_tw, ②status_affect, ③ac_basic
PDO
物件連接資料庫<?php
require_once 'connections/cn-prime.php';
?>
<select>
下拉選項<?php
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
?>
<form> <fieldset><legend>註冊 (申請) 帳號</legend> <ol> <li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds"></li> <li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合"></li> <li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"></li> <li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option>
<?php $stmt1=$prime->prepare("SELECT * FROM $tb_dt ORDER BY id"); if($stmt1->execute()){ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->district); } } ?>
</select></li> <li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>
<?php $stmt2=$prime->prepare("SELECT * FROM $tb_af ORDER BY id"); if($stmt2->execute()){ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->affect); } } ?>
</select></li> <li><button type="submit">建立</button></li> </ol> </fieldset> </form>
<?php
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
$regOK=true;
}
}
?>
<?php if(!empty($regOK)){ echo '<p>註冊成功</p>'; } ?>
<form method="post" action="
<?php echo basename(__FILE__); ?>
"> <fieldset><legend>註冊 (申請) 帳號</legend> <ol> <li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds"></li> <li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合"></li> <li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"></li> <li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option>
<?php $stmt1=$prime->prepare("SELECT * FROM $tb_dt ORDER BY id"); if($stmt1->execute()){ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->district); } } ?>
</select></li> <li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>
<?php $stmt2=$prime->prepare("SELECT * FROM $tb_af ORDER BY id"); if($stmt2->execute()){ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->affect); } } ?>
</select></li> <li><button type="submit" name="registering" value="1">建立</button></li> </ol> </fieldset> </form>
<?php
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
$sql2="SELECT count(*),email,password,nick,id FROM $tb_ac WHERE email=?";
$stmt4=$prime->prepare($sql2);
$stmt4->bindParam(1,$_POST['email']);
$stmt4->execute() or exit;
if($stmt4->fetchColumn()){
$isRegistered=true;
}
else{
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
$regOK=true;
}
}
}
?>
<?php if(!empty($regOK)){ echo '<p>註冊成功</p>'; } ?>
<form method="post" action="
<?php echo basename(__FILE__); ?>
"> <fieldset><legend>註冊 (申請) 帳號</legend> <ol> <li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds">
<?php if(!empty($isRegistered)){ echo '<label for="email" class="invalid" tabindex="0">帳號已有註冊。</label><a href="login.php">登入</a>?'; } ?>
</li> <li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合"></li> <li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"></li> <li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option>
<?php $stmt1=$prime->prepare("SELECT * FROM $tb_dt ORDER BY id"); if($stmt1->execute()){ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->district); } } ?>
</select></li> <li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>
<?php $stmt2=$prime->prepare("SELECT * FROM $tb_af ORDER BY id"); if($stmt2->execute()){ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->affect); } } ?>
</select></li> <li><button type="submit" name="registering" value="1">建立</button></li> </ol> </fieldset> </form>
<?php
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
$sql2="SELECT count(*),email,password,nick,id FROM $tb_ac WHERE email=?";
$stmt4=$prime->prepare($sql2);
$stmt4->bindParam(1,$_POST['email']);
$stmt4->execute() or exit;
if($stmt4->fetchColumn()){
$isRegistered=true;
}
else{
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$_POST['district'] or $_POST['district']=NULL;
$_POST['affect'] or $_POST['affect']=NULL;
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
$regOK=true;
}
}
}
?>
<?php if(!empty($regOK)){ echo '<p>註冊成功</p>'; } ?>
<form method="post" action="
<?php echo basename(__FILE__); ?>
"> <fieldset><legend>註冊 (申請) 帳號</legend> <ol> <li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds">
<?php if(!empty($isRegistered)){ echo '<label for="email" class="invalid" tabindex="0">帳號已有註冊。</label><a href="login.php">登入</a>?'; } ?>
</li> <li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合"></li> <li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"></li> <li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option>
<?php $stmt1=$prime->prepare("SELECT * FROM $tb_dt ORDER BY id"); if($stmt1->execute()){ if(!empty($_POST['district'])){ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['district']?' selected':'',$row->district); } } else{ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->district); } } } ?>
</select></li> <li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>
<?php $stmt2=$prime->prepare("SELECT * FROM $tb_af ORDER BY id"); if($stmt2->execute()){ if(!empty($_POST['affect'])){ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['affect']?' selected':'',$row->affect); } } else{ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->affect); } } } ?>
</select></li> <li><button type="submit" name="registering" value="1">建立</button></li> </ol> </fieldset> </form>
<?php
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
if(!empty($_POST['email'])&&!empty($_POST['password'])){
$sql2="SELECT count(*),email,password,nick,id FROM $tb_ac WHERE email=?";
$stmt4=$prime->prepare($sql2);
$stmt4->bindParam(1,$_POST['email']);
$stmt4->execute() or exit;
if($stmt4->fetchColumn()){
$isRegistered=true;
}
else{
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$_POST['nick'] or $_POST['nick']=NULL;
$_POST['district'] or $_POST['district']=NULL;
$_POST['affect'] or $_POST['affect']=NULL;
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
$regOK=true;
}
}
}
}
?>
<?php
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
if(!empty($_POST['email'])&&!empty($_POST['password'])){
if(filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
$sql2="SELECT count(*),email,password,nick,id FROM $tb_ac WHERE email=?";
$stmt4=$prime->prepare($sql2);
$stmt4->bindParam(1,$_POST['email']);
$stmt4->execute() or exit;
if($stmt4->fetchColumn()){
$isRegistered=true;
}
else{
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$_POST['nick'] or $_POST['nick']=NULL;
$_POST['district'] or $_POST['district']=NULL;
$_POST['affect'] or $_POST['affect']=NULL;
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
$regOK=true;
}
}
}
}
}
?>
<?php if(!empty($regOK)){ echo '<p>註冊成功</p>'; } ?>
<form method="post" action="
<?php echo basename(__FILE__); ?>
"> <fieldset><legend>註冊 (申請) 帳號</legend> <ol> <li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds">
<?php if(filter_has_var(INPUT_POST,'email')&&!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ echo '<label for="email" class="invalid" tabindex="0">須填入正確電子信箱帳號。</label>'; } elseif(!empty($isRegistered)){ echo '<label for="email" class="invalid" tabindex="0">帳號已有註冊。</label><a href="login.php">登入</a>?'; } ?>
</li> <li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合"></li> <li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"></li> <li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option>
<?php $stmt1=$prime->prepare("SELECT * FROM $tb_dt ORDER BY id"); if($stmt1->execute()){ if(!empty($_POST['district'])){ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['district']?' selected':'',$row->district); } } else{ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->district); } } } ?>
</select></li> <li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>
<?php $stmt2=$prime->prepare("SELECT * FROM $tb_af ORDER BY id"); if($stmt2->execute()){ if(!empty($_POST['affect'])){ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['affect']?' selected':'',$row->affect); } } else{ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->affect); } } } ?>
</select></li> <li><button type="submit" name="registering" value="1">建立</button></li> </ol> </fieldset> </form>
<?php if(!empty($regOK)){ echo '<p>註冊成功</p>'; } ?>
<form method="post" action="
<?php echo basename(__FILE__); ?>
"> <fieldset><legend>註冊 (申請) 帳號</legend> <ol> <li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds"
<?php if(!empty($_POST['email'])) echo ' value="'.$_POST['email'].'"'; ?>
>
<?php if(filter_has_var(INPUT_POST,'email')&&!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ echo '<label for="email" class="invalid" tabindex="0">須填入正確電子信箱帳號。</label>'; } elseif(!empty($isRegistered)){ echo '<label for="email" class="invalid" tabindex="0">帳號已有註冊。</label><a href="login.php">登入</a>?'; } ?>
</li> <li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合"></li> <li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"
<?php if(!empty($_POST['nick'])) echo ' value="'.$_POST['nick'].'"'; ?>
></li> <li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option>
<?php $stmt1=$prime->prepare("SELECT * FROM $tb_dt ORDER BY id"); if($stmt1->execute()){ if(!empty($_POST['district'])){ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['district']?' selected':'',$row->district); } } else{ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->district); } } } ?>
</select></li> <li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>
<?php $stmt2=$prime->prepare("SELECT * FROM $tb_af ORDER BY id"); if($stmt2->execute()){ if(!empty($_POST['affect'])){ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['affect']?' selected':'',$row->affect); } } else{ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->affect); } } } ?>
</select></li> <li><button type="submit" name="registering" value="1">建立</button></li> </ol> </fieldset> </form>
<?php
/**
* v.0.2.0 latest:2014/11/16
* ©webchain(不惑仔), all rights reserved. Free for commercial and personal use.
*/
class validux{
public static function isAlphanumMixed($subject,$minLength=3,$maxLength=''){
$p='/(?=^[A-Za-z0-9]{'.$minLength.','.$maxLength.'}$)((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]))^.*$/';
return (bool)preg_match($p,$subject);
}
}
?>
<?php
function autoloadClass($class){require_once "classes/$class.php";}spl_autoload_register('autoloadClass');
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
if(!empty($_POST['email'])&&!empty($_POST['password'])){
if(filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
$sql2="SELECT count(*),email,password,nick,id FROM $tb_ac WHERE email=?";
$stmt4=$prime->prepare($sql2);
$stmt4->bindParam(1,$_POST['email']);
$stmt4->execute() or exit;
if($stmt4->fetchColumn()){
$isRegistered=true;
}
elseif(validux::isAlphanumMixed($_POST['password'],6,18)){
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$_POST['nick'] or $_POST['nick']=NULL;
$_POST['district'] or $_POST['district']=NULL;
$_POST['affect'] or $_POST['affect']=NULL;
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
$regOK=true;
}
}
}
}
}
?>
<?php if(!empty($regOK)){ echo '<p>註冊成功</p>'; } ?>
<form method="post" action="
<?php echo basename(__FILE__); ?>
"> <fieldset><legend>註冊 (申請) 帳號</legend> <ol> <li><label for="email">帳號 (email) :</label><input id="email" name="email" type="email" maxlength="120" placeholder="thanks@lot.freinds"
<?php if(!empty($_POST['email'])) echo ' value="'.$_POST['email'].'"'; ?>
>
<?php if(filter_has_var(INPUT_POST,'email')&&!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ echo '<label for="email" class="invalid" tabindex="0">須填入正確電子信箱帳號。</label>'; } elseif(!empty($isRegistered)){ echo '<label for="email" class="invalid" tabindex="0">帳號已有註冊。</label><a href="login.php">登入</a>?'; } ?>
</li> <li><label for="pwd">密碼:</label><input id="pwd" name="password" type="password" maxlength="18" placeholder="6-18大小寫字母數字混合">
<?php if(filter_has_var(INPUT_POST,'password')&&!validux::isAlphanumMixed($_POST['password'],6,18)) echo '<label for="pwd">須填入有效密碼。</label>' ?>
</li> <li><label for="nick">暱稱:</label><input id="nick" name="nick" type="text" maxlength="30"
<?php if(!empty($_POST['nick'])) echo ' value="'.$_POST['nick'].'"'; ?>
></li> <li><label for="district">居住區:</label><select id="district" name="district"><option value="0">縣市</option>
<?php $stmt1=$prime->prepare("SELECT * FROM $tb_dt ORDER BY id"); if($stmt1->execute()){ if(!empty($_POST['district'])){ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['district']?' selected':'',$row->district); } } else{ while($row=$stmt1->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->district); } } } ?>
</select></li> <li><label for="affect">感情:</label><select id="affect" name="affect"><option value="0">狀況</option>
<?php $stmt2=$prime->prepare("SELECT * FROM $tb_af ORDER BY id"); if($stmt2->execute()){ if(!empty($_POST['affect'])){ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s"%s>%s</option>',$row->id,$row->id==$_POST['affect']?' selected':'',$row->affect); } } else{ while($row=$stmt2->fetch(PDO::FETCH_LAZY)){ printf('<option value="%s">%s</option>',$row->id,$row->affect); } } } ?>
</select></li> <li><button type="submit" name="registering" value="1">建立</button></li> </ol> </fieldset> </form>
<?php
function autoloadClass($class){require_once "classes/$class.php";}spl_autoload_register('autoloadClass');
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
if(!empty($_POST['email'])&&!empty($_POST['password'])){
if(filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
$sql2="SELECT count(*),email,password,nick,id FROM $tb_ac WHERE email=?";
$stmt4=$prime->prepare($sql2);
$stmt4->bindParam(1,$_POST['email']);
$stmt4->execute() or exit;
if($stmt4->fetchColumn()){
$isRegistered=true;
}
elseif(validux::isAlphanumMixed($_POST['password'],6,18)){
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$_POST['nick'] or $_POST['nick']=NULL;
$_POST['district'] or $_POST['district']=NULL;
$_POST['affect'] or $_POST['affect']=NULL;
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
if(filter_has_var(INPUT_COOKIE,'pathToAuth')){
$pathRef=$_COOKIE['pathToAuth'];
setcookie('pathToAuth','',time()-3600);
header("Location:$pathRef".'?auth=1');
}
else{
header("Location:http://localhost/login.php?auth=1");
}
}
}
}
}
}
?>
#另移除註冊成功訊息
<?php
function autoloadClass($class){require_once "classes/$class.php";}spl_autoload_register('autoloadClass');
require_once 'connections/cn-prime.php';
$tb_dt='district_tw';
$tb_af='status_affect';
$tb_ac='ac_basic';
if(filter_has_var(INPUT_POST,'registering')){
if(!empty($_POST['email'])&&!empty($_POST['password'])){
if(filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
$sql2="SELECT count(*),email,password,nick,id FROM $tb_ac WHERE email=?";
$stmt4=$prime->prepare($sql2);
$stmt4->bindParam(1,$_POST['email']);
$stmt4->execute() or exit;
if($stmt4->fetchColumn()){
$isRegistered=true;
}
elseif(validux::isAlphanumMixed($_POST['password'],6,18)){
$sql1="INSERT INTO $tb_ac (email,password,nick,district,affect) VALUES (:email,:password,:nick,:district,:affect)";
$stmt3=$prime->prepare($sql1);
$_POST['nick'] or $_POST['nick']=NULL;
$_POST['district'] or $_POST['district']=NULL;
$_POST['affect'] or $_POST['affect']=NULL;
$stmt3->bindParam(':email',$_POST['email']);
$stmt3->bindParam(':password',$_POST['password']);
$stmt3->bindParam(':nick',$_POST['nick']);
$stmt3->bindParam(':district',$_POST['district'],PDO::PARAM_INT);
$stmt3->bindParam(':affect',$_POST['affect'],PDO::PARAM_INT);
if($stmt3->execute()){
if($stmt4->execute()){
session_start();
$_SESSION=[];
session_regenerate_id(true);
$row=$stmt4->fetch(PDO::FETCH_OBJ);
$_SESSION['logAccount']=$row->email;
$_SESSION['logNickname']=$row->nick?$row->nick:'隱名埋姓';
$_SESSION['logid']=$row->id;
if(filter_has_var(INPUT_COOKIE,'pathToAuth')){
$pathRef=$_COOKIE['pathToAuth'];
setcookie('pathToAuth','',time()-3600);
header("Location:$pathRef".'?auth=1');
}
else{
header("Location:http://localhost/login.php?auth=1");
}
}
}
}
}
}
}
?>
更新日期: