防止sql注入

SQL注入:
是从正常的WWW端口访问,而且表面看起来跟一般的Web页面访问没什么区别,所以目前市面的防火墙都不会对SQL注入发出警报,如果管理员没查看IIS日志的习惯,可能被入侵很长时间都不会发觉。

但是,SQL注入的手法相当灵活,在注入的时候会碰到很多意外的情况。能不能根据具体情况进行分析,构造巧妙的SQL语句,从而成功获取想要的数据,是相当重要的。

下面是防止sql注入的语句:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>防止SQL注入的登录页面</title>
<script type="text/javascript">
    function Mycheck(str){
      var mess="不允许输入的字符:\r\n";
      var mark="yes";
      if(str.indexOf(";")>=0){
          mark="no";
          mess+=" ; ";
      }
      if(str.indexOf("&")>=0){
          mark="no";
          mess+=" & ";
      }
      if(str.indexOf("<")>=0){
          mark="no";
          mess+=" < ";
      }
      if(str.indexOf(">")>=0){
          mark="no";
          mess+=" > ";
      }
      if(str.indexOf("--")>=0){
          mark="no";
          mess+=" -- ";
      }
      if(str.indexOf("/")>=0){
          mark="no";
          mess+=" / ";
      }
      if(str.indexOf("%")>=0){
          mark="no";
          mess+=" % ";
      }
      if(str.indexOf("'")>=0){
          mark="no";
          mess+=" ' ";
      }
      if(mark=="no"){
          alert(mess);
          return false;
      }
      else return
          return true;     
    }
</script>
</head>
<body style="font-size:12px">
<table width="382" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="99" background="images/login_01.jpg">&nbsp;</td>
  </tr>
  <tr>
    <td height="160" bgcolor="#FEF7C3"><table width="300" border="0" align="center" cellpadding="3" cellspacing="0">
        <form name="form1" onSubmit="Mycheck(form1.txt_name.value)">
          <tr>
            <td height="22" colspan="2" align="center">&nbsp;</td>
          </tr>
          <tr>
            <td height="22" align="right">管理员:</td>
            <td height="22"><input name="txt_name" type="text" class="textbox" id="txt_name" size="18" maxlength="50"></td>
          </tr>
          <tr>
            <td height="22" align="right">密
              码:</td>
            <td height="22"><input name="txt_passwd" type="password" class="textbox" id="txt_passwd" size="19" maxlength="50"></td>
          </tr>
          <tr>
            <td height="22" colspan="2" align="center"><input name="login" type="submit" id="login" value="登 录" class="button">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type="reset" name="Submit2" value="重 置" class="button"></td>
          </tr>
        </form>
    </table></td>
  </tr>
</table>
</body>
</html>

posted on 2009-07-28 17:41  ミ咯咯①笑。  阅读(450)  评论(0编辑  收藏  举报

导航