简单的PHP注册页面

注册页面
注册成功返回页面

index.php

<?php
$string = 'qwertyuiopasdfghjklzxcvbnm1234567890';
$code   = '';
for ($i = 1; $i <= 4; $i++) {
    $code .= '<span style="color:rgb(' . mt_rand(0, 255) . ',' . mt_rand(0, 255) . ',' . mt_rand(0, 255) . ')"><strong>' . $string{mt_rand(0, strlen($string) - 1)} . '</strong></span>';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>注册页面</title>
</head>
<body>
    <h1>注册页面</h1>
    <form action="doAction.php" method="post">
        <table border="1" cellspaceing="0" cellpadding="0" width="80%" bgcolor="#ABCDEF">
            <tr>
                <td align="right">用户名</td>
                <td><input type="text" name="username" placeholder="请输入合法的用户名" id="">用户名以字母开始,且长度为6-10</td>
            </tr>
            <tr>
                <td align="right">密码</td>
                <td><input type="password" name="password" placeholder="请输入密码">密码长度为6~10</td>
            </tr>
            <tr>
                <td align="right">确认密码</td>
                <td><input type="password" name="password1" id="" placeholder="请输入确认密码">再次输入密码</td>
            </tr>
            <tr>
                <td align="right">邮箱</td>
                <td><input type="text" name="email" placeholder="请输入合法邮箱" id="">邮箱</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
                    <input type="checkbox" name="fav[]" id="" value="c++">c++ <br>
                    <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">ionic
                </td>
            </tr>
            <tr>
                <td align="right">验证码</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="注册"></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  = strtolower($_POST['verify']);
$verify1 = strtolower($_POST['verify1']);
$char    = $username{0};
$ascii   = ord($char);
if (!(($ascii >= 65 && $ascii <= 90) || ($ascii >= 97 && $ascii <= 122))) {
    exit('用户名首字母非字母开头<br/>');
}
$userLen = strlen($username);
if ($userLen < 6 || $userLen > 10) {
    exit('用户名长度不符合规范<br/>');
}

$pwdLen = strlen($password);
if ($pwdLen == 0) {
    exit('密码不能为空<br/>');
}
if ($pwdLen < 6 || $pwdLen > 10) {
    die('密码长度不符合规范<br/>');
}
if (strcmp($password, $password1) != 0) {
    exit('再次密碼不一致<br/>');
}

if (strpos($email, '@') == false) {
    exit('非法郵箱<br/>');
}
if ($verify !== $verify1) {
    exit('验证码错误<br/>');
}
echo '恭喜注册成功,用户信息如下:<br/>';
$userInfo = <<<EOF
<table border='1' cellspacing='0' cellpadding='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;
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值