php實現發送驗證碼並實現驗證

博主在參加比賽時需要使用郵箱驗證碼來驗證用戶信息,因爲之前有過類似的經驗,便寫了一個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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章