php做的主页验证码

来源:互联网 发布:下载数据恢复 编辑:程序博客网 时间:2024/05/17 01:30
 这是做的一个主页,有点简陋,但还算不错。。

<body>
<form name="form1"  method="post"  action="check.php" >
  <table  border="1" align="center" cellpadding="0" cellspacing="0" >
    <tr>
      <td width="70" align="right"><span class="STYLE4">用户名</span></td>
      <td width="100" align="left"><input type="text" name="username" id="username"></td>
    </tr>
    <tr>
      <td align="right"><span class="STYLE4">密码</span></td>
      <td align="left"><input type="password" name="password" id="password"></td>
    </tr>
<tr>
  <td width="70" align="right"><span class="STYLE4">验证码</span></td>
  <td>

    <input type="text" name="input1" >   <img src="code.php"><hr>
</td>

</tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td align="left"><input type="submit" name="submit" value="登录" id="submit">
          <input type="reset" name="reset" id="reset" /></td>
    </tr>
  </table>
</form>
</div>
</body>

这里面的check.php
<?php
session_start();
include('conn.php');
[url=mailtoa=@strtoupper($_POST[]$a=@strtoupper($_POST["input1[/url]"]); //接受输入的验证码
[url=mailtob=@strtoupper($_SESSION[]$b=@strtoupper($_SESSION["code"]);//[/url]接受验证码
if($_POST['username']!=""&&$_POST['password']!=""){
//定义sql
$sql="SELECT * FROM admin where username='".$_POST['username']."' and password='".$_POST['password']."'";//判断用户名及密码不为空
$rs=mysql_query($sql);
if(mysql_num_rows($rs)){

  
  $_SESSION['user']=$_POST['username'];
   
   if($a==$b){      //用户名及密码判断之后 判断验证码
   ?>
   <script type="text/javascript">
  <!--
     alert("登陆成功,确定后跳转到首页!");
     location="header.php";
  //-->
  </script>   
   <?php
   }else{
   ?>   
   <script type="text/javascript">
   alert ("验证码错误!");location="index.php";
   </script>
  <?php
  }
  ?>
   
  <?php
}else{
  ?>  
  <script type="text/javascript">
   alert("登陆失败,用户名或者密码错误!");
   location="index.php";
  </script>
  <?php
  
}

}else {
?>
<script type="text/javascript">
alert("用户名或者密码不能为空!~");
location="index.php";
</script>
<?php
}
?>