join
implode
修改代碼
$fav = $_POST['fav'];
if (!empty($fav)) {
$favStr = join(',', $fav);
}
$password = md5($password);
$userInfo = <<<EOF
<table border="1" cellpadding="0" cellspacing="0" width="70%">
<tr>
<td>用戶名</td>
<td>密碼</td>
<td>郵箱</td>
<td>興趣愛好</td>
</tr>
<tr>
<td>{$username}</td>
<td>{$password}</td>
<td>{$email}</td>
<td>{$favStr}</td>
</tr>
</table>
EOF;
echo $userInfo;
reg.php
<?php
$string = "ABCDEFGHIJKLMNOPQRSJUVWXYZ1234567890";
$code = "";
for ($i = 1; $i <= 4; $i++) {
$code .= '<span style="color:rgb(' . mt_rand(0, 255) . ',' . mt_rand(0, 255) . ',' . mt_rand(0, 255) . ')">' . $string{mt_rand(0, strlen($string) - 1)} . '</span>';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注冊(cè)頁(yè)面</title>
</head>
<body>
<h1>慕課網(wǎng)注冊(cè)頁(yè)面</h1>
<form method="post" action="doAction.php">
<table border="1" cellspacing="0" cellpadding="0" width="80%" bgcolor="#ABCDEF">
<tr>
<td align="right">用戶名</td>
<td><input type="username" name="username" id="" placeholder="請(qǐng)輸入合法用戶名...">用戶名首字母以字母開始,并且長(zhǎng)度6~10</td>
</tr>
<tr>
<td align="right">密碼</td>
<td><input type="password" name="password" placeholder="請(qǐng)密碼...">密碼不能為空,長(zhǎng)度6~10</td>
</tr>
<tr>
<td align="right">確認(rèn)密碼</td>
<td><input type="password" name="password1" id="" placeholder="請(qǐng)輸入確認(rèn)密碼...">兩次密碼一致</td>
</tr>
<tr>
<td align="right">郵箱</td>
<td><input type="text" name="email" id="" placeholder="請(qǐng)輸入合法郵箱">郵箱必須包含@,382771946@qq.com</td>
</tr>
<tr>
<td align="right">興趣愛好</td>
<td>
<input type="checkbox" name="fav[]" id="" value="php">PHP
<input type="checkbox" name="fav[]" id="" value="java">Java
<input type="checkbox" name="fav[]" id="" value="ios">Ios
<input type="checkbox" name="fav[]" id="" value="c">C語(yǔ)言
<input type="checkbox" name="fav[]" id="" value="c++">C++
<input type="checkbox" name="fav[]" id="" value="swift">Swift
<input type="checkbox" name="fav[]" id="" value="meteor">Meteor
<input type="checkbox" name="fav[]" id="" value="nodejs">NodeJS
<input type="checkbox" name="fav[]" id="" value="ionic">Iconic
</td>
</tr>
<tr>
<td align="right">驗(yàn)證碼</td>
<td>
<input type="text" name="verify"><?php echo $code ?>
<input type="hidden" name="verify1" value='<?php echo strip_tags($code) ?>'></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="注冊(cè)"></td>
</tr>
</table>
</form>
</body>
</html>
doAction.php
<?php
header("content-type:text/html;charset=utf-8");
$username = $_POST['username'];
$password = $_POST['password'];
$password1 = $_POST['password1'];
$email = $_POST['email'];
$fav = $_POST['fav'];
if (!empty($fav)) {
$favStr = join(',', $fav);
}
$verify = trim(strtolower($_POST['verify']));
$verify1 = trim(strtolower($_POST['verify1']));
$redirectUrl = '<a href="reg.php" > 重新注冊(cè)</a > ';
//$char = $username{0};
$char = substr($username, 0, 1);
$ascii = ord($char);
if (!(($ascii >= 65 && $ascii <= 90) || ($ascii >= 97 && $ascii <= 122))) {
exit('用戶名首字母不是以字母開始' . $redirectUrl);
}
$userLen = strlen($username);
if ($userLen < 6 || $userLen > 10) {
exit('用戶名長(zhǎng)度不符合規(guī)范 <br/>' . $redirectUrl);
}
$pwdLen = strlen($password);
if ($pwdLen == 0) {
exit('密碼不能為空<br/>' . $redirectUrl);
}
if ($pwdLen < 6 || $pwdLen > 10) {
die("密碼長(zhǎng)度不符合規(guī)范" . $redirectUrl);
}
//if ($password !== $password1) {
// exit("兩次密碼不一致<br/>" . $redirectUrl);
//}
if (strcmp($password, $password1) !== 0) {
exit("兩次密碼不一致<br/>" . $redirectUrl);
}
//位置0也是false
if (strpos($email, '@') == false) {
exit("非法郵箱<br/>" . $redirectUrl);
}
if ($verify1 !== $verify) {
exit("驗(yàn)證碼錯(cuò)誤<br/>" . $redirectUrl);
}
echo "恭喜您注冊(cè)成功<br/>";
$password = md5($password);
$userInfo = <<<EOF
<table border="1" cellpadding="0" cellspacing="0" width="70%">
<tr>
<td>用戶名</td>
<td>密碼</td>
<td>郵箱</td>
<td>興趣愛好</td>
</tr>
<tr>
<td>{$username}</td>
<td>{$password}</td>
<td>{$email}</td>
<td>{$favStr}</td>
</tr>
</table>
EOF;
echo $userInfo;
?>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者