博主在参加比赛时需要使用邮箱验证码来验证用户信息,因为之前有过类似的经验,便写了一个php验证码获取并实现验证的程序,可独立运行。以下是实现的界面和大致代码程序:
有需要的可以留言给我哟
<html>
<head>
<meta charset="UTF-8">
<title></title>
<!--引入css样式表-->
<link rel=stylesheet href="./css/style.css">
<style>
.x{
border-left:none;
border-right:none;
border-top:none;
border-bottom:1px solid #cba1d2;
}
.x:focus{
outline: none;
border-bottom: 1px solid #fafafa;
}
</style>
</head>
<body>
<center><table border="0" cellpadding="10" >
<tr><td bgcolor="#1eafed" colspan=3 style="background-color:#1eafed;border:none;border-radius:10px;"><h1><font color=white>密码修改</h1></td></tr>
<tr><td colspan=3 height=10></td></tr>
<tr><form method="post" action="email1.php">
<td align="right"><img src="images/2.jpg" width=30 height=30></td>
<td colspan=2>
<input id="eamil" class="x" name="email" style="height:35px;width:300px;outline:none" placeholder="@qq.com" type="text" size="25" class="inputBg" required="required" /><span style="color:#FF0000"> *</span>
</td>
</tr>
<tr>
<td colspan=3>
<input type="submit" value=" 确认发送 " style="background-color:#ffcd3c;border:none;height:50px;width:420px;border-radius:10px;color:#929aab;font-size:24px;color:white;" >
</td>
</tr>
</table></center>
<script type="text/javascript">
//倒计时
var countdown=60;
function settime(val) {
if (countdown == 0) {
val.removeAttribute("disabled");
val.value="获取验证码";
countdown = 60;
return false;
} else {
val.setAttribute("disabled", true);
val.value="重新发送(" + countdown + ")";
countdown--;
}
setTimeout(function() {
settime(val);
},1000);
}
</script>
<style>
.ico{
height:30px;
width:34px;
background:url(images/ico.jpg) ;
top:10px;
left:8.5%;
opacity:0.7;
}
#in{ display:block;
height:30px;
width:10%;}
</style>
</body>
<?php
session_start();
if($_SERVER['REQUEST_METHOD']=='POST')
{
$code=$_SESSION["vcode"];
$email=$_SESSION["email"];
unset($_SESSION["code"]);
$code1=$_POST['code'];
echo $code;
echo $email;
echo $code1;
if(strtolower($code) === strtolower($code1)){
$oldpassword=$_POST['oldpassword'];
$newpassword=$_POST['newpassword'];
if(!(is_null($email)and is_null($oldpassword))){
$conn = new mysqli("localhost", "root", "px980305", "hall")or die ("You cannot connect the database!<br>".mysqli_error());
$sql="update user set password='$oldpassword' where tel='$email' ";
if ($conn->query($sql) === TRUE) {
//echo "<a href='denglu.php'>返回登录页面</a>";
echo "<font color='red' szie='6'>密码修改成功,3秒后跳转到登陆界面</font>";
header('refresh:3;url=denglu.html');
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
$conn->close();
exit;
}
}
else echo "验证码错误,请重新修改";
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<!--引入css样式表-->
<link rel=stylesheet href="./css/style.css">
<style>
.x{
border-left:none;
border-right:none;
border-top:none;
border-bottom:1px solid #cba1d2;
}
.x:focus{
outline: none;
border-bottom: 1px solid #fafafa;
}
</style>
</head>
<body>
<center><table border="0" cellpadding="10" >
<tr><td bgcolor="#1eafed" colspan=3 style="background-color:#1eafed;border:none;border-radius:10px;"><h1><font color=white>密码修改</h1></td></tr>
<tr><td colspan=3 height=10></td></tr>
<form method="post" action="forget.php">
</tr>
<tr>
<td align="right"><font color="#7d7d7d"><strong><img src="images/3.jpg" width=30 height=30></td>
<td align="left"colspan=2 >
<input type="text" class="x" id="code" name="code" style="height:35px;width:300px;outline:none" class="inputBg" autocomplete="off" placeholder="输入邮箱验证码" size="25" required="required" />
</td>
</tr>
<tr>
<td align="right"><font color="#7d7d7d"><strong><img src="images/1.jpg" width=30 height=30></td>
<td colspan=2>
<input id="oldpassword" class="x" name="oldpassword" style="height:35px;width:300px;outline:none" placeholder="输入6-10位密码" type="text" size="25" class="inputBg" /><span style="color:#FF0000" required="required" > *</span>
</td>
</tr>
<tr>
<td align="right"><font color="#7d7d7d"><strong><img src="images/4.jpg" width=30 height=30></td>
<td colspan=2>
<input id="newpassword" class="x" name="newpassword" style="height:35px;width:300px;outline:none" placeholder="输入6-10位密码" type="text" size="25" class="inputBg" /><span style="color:#FF0000" required="required" > *</span>
</td>
</tr>
<tr>
<td colspan=3>
<input type="submit" value=" 确认修改 " style="background-color:#ffcd3c;border:none;height:50px;width:380px;border-radius:10px;color:#929aab;font-size:24px;color:white;" >
</td>
</tr>
</table></center>
</body>