php根据问题取回密码功能的实现代码

发布时间:2019-11-06编辑:脚本学堂
为大家介绍一个根据提问问题的答案取回密码的实现代码,有需要的朋友,可以参考下。

很多程序中都会有注册用户的功能,当然都会有忘记密码取回这一项,为大家提供一段代码,有需要的朋友,可以看看。

第一步:
 

复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>根据问题取回密码_www.jb200.com</title> 
    </head>     
    <body> 
    <form action="wangjimima1.php" method="post" name="form1" id="form1"> 
      <table width="40%"  border="0" align="center" cellpadding="5" cellspacing="0" class="biaoge"> 
        <tr> 
          <td height="20" colspan="2" class="danyuange"><div align="center">请输入您的用户名</div></td> 
        </tr> 
        <tr> 
          <td width="24%" height="20" class="left"><div align="center">用户名 </div></td> 
          <td width="76%" class="danyuange"><div align="center"> 
            <input name="username" type="text" id="username" /> 
          </div></td> 
        </tr> 
        <tr> 
          <td height="20" colspan="2"><div align="center">   
 <input type="submit" name="Submit" value="下一步" />
            <input type="reset" name="Submit" value="取消" /> 
          </div></td> 
        </tr> 
      </table> 
    </form> 
    </body> 
    </html> 

第二步:
 

复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>取回密码2</title> 
</head>
    <body> 
    <?php 
    require_once ('conn.php'); 
     
     $sql = "select * from member where username='$_POST[username]'"; 
     $result =mysql_query($sql,$conn); 
    if ($rs =mysql_fetch_array($result)){ 
     
     ?> 
    <form action="wangjimima2.php" method="post" name="form1" id="form1"> 
    <?php 
        $sql = "select * from member where username='$_POST[username]'"; 
        $result =mysql_query($sql,$conn); 
        $rs =mysql_fetch_array($result); 
     
     ?> 
        <table width="45%"  border="0" align="center" cellpadding="5" cellspacing="0" class="biaoge"> 
          <tr> 
            <td colspan="2" class="right"><div align="center"><span class="style18">请输入根据提示问题输入问题答案</span></div></td> 
          </tr> 
          <tr> 
            <td width="26%" class="left"><div align="right" class="style15"> 
              <div align="center">用户名</div> 
            </div></td> 
            <td width="74%" class="right"><?=$_POST[username]?> 
                <input name="id" type="hidden" id="id" value="<?=$rs["id"]?>" /></td> 
          </tr> 
          <tr> 
            <td class="left"><div align="right" class="style15"> 
              <div align="center">密码提示</div> 
            </div></td> 
            <td class="right"><?=$rs["problem"]?></td> 
          </tr> 
          <tr> 
            <td class="left"><div align="right" class="style16"> 
              <div align="center">问题答案</div> 
            </div></td> 
            <td class="right"><input name="answer" type="text" id="answer" /></td> 
          </tr> 
          <tr> 
            <td colspan="2"><div align="left"><input type="submit" name="Submit" value="提交" />
              <input type="reset" name="Submit" value="重置" /> 
            </div></td> 
          </tr> 
        </table> 
      </form> 
       <?php  
       }else{ 
         echo "<mce:script language=javascript><!-- 
    "; 
      echo "alert('没有此用户,请确认你所输入的用户名是否正确!');"; 
      echo "javascript:history.go(-1);"; 
      echo " 
    // --></mce:script>"; //用javascript脚本提示用户; 
    } 
       ?> 
    </body>
    </html>

第三步
 

复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>取回密码3</title> 
    </head>     
    <body> 
<?php 
    require_once ('conn.php');     
    $sql = "select * from member where id=$_POST[id]"; 
    $result =mysql_query($sql,$conn); 
    $rs =mysql_fetch_array($result);
?> 
        <br /> 
      <table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0"> 
        <tr> 
          <td><div align="center"><span class="style12"><strong>恭喜您,您的密码以找回,请您紧记,切勿忘记!</strong></span></div></td> 
        </tr> 
      </table> 
      <form action="wangjimima2.php" method="post" name="form1" id="form1"> 
        <table width="50%"  border="0" align="center" cellpadding="5" cellspacing="0" class="biaoge"> 
          <tr> 
            <td colspan="2" class="right"><div align="center"><span class="style1 style12">这是您的用户名和密码,请勿忘记!</span></div></td> 
          </tr> 
          <tr> 
            <td width="26%" class="left"><div align="center">用 户 名</div></td> 
            <td width="74%" class="right">  
                <?=$rs[username]?></td> 
          </tr> 
          <tr> 
            <td class="left"><div align="center">密    码</div></td> 
            <td class="right">  
                <? 
           if ($_POST["answer"]==$rs["answer"]) { 
           echo $rs["password"]; 
           session_register("username"); 
           $username=$rs[username]; 
           $aaa=$rs[username]; 
            
              }else{ 
           echo("<mce:script type='text/javascript'><!-- 
     alert('对不起,您输入的密码提示答案错误!');location.href='wangjimima.php'; 
    // --></mce:script>");       
             } 
     
           ?></td> 
          </tr> 
          <tr> 
            <td colspan="2" class="left"><div align="center"><a href="index.php" mce_href="index.php" class="c">返回首页</a></div></td> 
          </tr> 
        </table> 
      </form> 
    </body> 
    </html>