<?php
if(!empty($_POST['username']) && !empty($_POST['user_password']) && !empty($_POST['user_password_s']) && !empty($_POST['code'])){
if((ord(ucfirst($_POST['username']){0}) < 65) || (ord(ucfirst($_POST['username']){0}) > 90 )){
exit(json_encode([
'msg'=>'用户名不合法'
]));
}
if(strcmp($_POST['user_password'],$_POST['user_password_s'])){
exit(json_encode([
'msg'=>'密码不一致'
]));
}
if(strcasecmp($code_s,$code)){
exit(json_encode([
'msg'=>'验证码错误'
]));
}
exit(json_encode([
'msg'=>'注册成功'
]));
}else{
$code_s = substr(md5(mt_rand()),0,5);
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用户登陆</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container theme-showcase" role="main">
<br>
<div class="jumbotron">
<h2><b>用户登陆</b></h2>
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">账 号</span>
</div>
<input type="text" class="form-control" id="username" placeholder="请输入注册账号" required="">
</div>
<br>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">密 码</span>
</div>
<input type="password" class="form-control" id="user_password" placeholder="请输入注册密码" required="">
</div>
<br>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">确认密码</span>
</div>
<input type="password" class="form-control" id="user_password_s" placeholder="请再次输入注册密码" required="">
</div>
<br>
<div class="row">
<div class="col">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">验 证 码</span>
</div>
<input type="text" class="form-control" id="code" placeholder="请输入验证" required="" >
</div>
</div>
<div class="col">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><?=$code_s?></span>
</div>
</div>
</div>
</div>
<br>
<button type="button" class="btn btn-primary btn-lg btn-block" id="Pots_go">注册</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script>
$(function($) {
$('#Pots_go').on('click', function () {
$.ajax({
url:'index.php',
dataType:'json',
type:'POST',
data:{
'username':$('#username').val(),
'user_password':$('#user_password').val(),
'user_password_s':$('#user_password_s').val(),
'code':$('#code').val()
},
success: function (data, status) {
alert(data.msg);
},
error: function (request, error, thrown) {
}
})
})
})
</Script>
</body>
</html>