$username = $_POST['username'];
$query = "select * from auth where username = '".$username."'";
echo $query;
$db = new mysqli('localhost', 'demo', ‘demo', ‘demodemo');
$result = $db->query($query);
if ($result && $result->num_rows) {
echo "<br />Logged in successfully";
} else {
echo "<br />Login failed";
}上面的代码,在第一行没有过滤或转义用户输入的值($_POST['username'])。因此查询可能会失败,甚至会损坏数据库,这要看$username是否包含变换你的SQL语句到别的东西上。 $query = 'select name, district from city where countrycode=?';
if ($stmt = $db->prepare($query) )
{
$countrycode = 'hk';
$stmt->bind_param("s", $countrycode);
$stmt->execute();
$stmt->bind_result($name, $district);
while ( $stmt ($stmt->fetch() ){
echo $name.', '.$district;
echo '<br />';
}
$stmt->close();
}2、XSS攻击 <?php
if (file_exists('comments')) {
$comments = get_saved_contents_from_file('comments');
} else {
$comments = '';
}
if (isset($_POST['comment'])) {
$comments .= '<br />' . $_POST['comment'];
save_contents_to_file('comments', $comments);
}
?>输出内容给(另一个)用户 <form action='xss.php' method='POST'>
Enter your comments here: <br />
<textarea name='comment'></textarea> <br />
<input type='submit' value='Post comment' />
</form><hr /><br />
<?php echo $comments; ?>将会发生什么事? <form>Choose theme:
<select name = theme>
<option value = blue>Blue</option>
<option value = green>Green</option>
<option value = red>Red</option>
</select>
<input type = submit>
</form>
<?php
if($theme) {
require($theme.'.txt');
}
?>在上面的例子中,通过传递用户输入的一个文件名或文件名的一部分,来包含以"http://"开头的文件。ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。