SQL注入原理是通过字符串的拼接组合来实现黑客想要实现的结果
以下为一个简单的注入Demo,当用户名填写为 ' or 1=1# 的时候,SQL语句变为
select * from users where username='' or 1=1#' and password=''
#后面内容为注释,这句话就相当于 select * form users; 从而实现了注入效果
<html>
<head>
<title>Sql注入演示</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body >
<form action="" method="post">
<fieldset >
<legend>Sql注入演示</legend>
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="text" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="提交"></td>
<td><input type="reset" value="重置"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
<?php
if($_POST['username']){
$conn=@mysql_connect("localhost",'root','') or die("数据库连接失败!");;
mysql_select_db("test",$conn) or die("您要选择的数据库不存在");
$name=$_POST['username'];
$pwd=md5($_POST['password']);
$sql="select * from users where username='$name' and password='$pwd'";
echo $sql."<br><br>";
$query=mysql_query($sql);
$arr=mysql_fetch_array($query);
if(is_array($arr)){
echo "登陆成功!";
}else{
echo "您的用户名或密码输入有误,请重新登录!";
}
}
?>
原文链接 http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2012/0210/9803.html