不方便查看的话,复制到本地即可
<!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=utf-8" />
<title>Less-17 Update Query- Error based - String</title>
</head>
<body bgcolor="#000000">
<div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"><font color="#FFFF00"> [PASSWORD RESET] </br></font> <font color="#FF0000"> Dhakkan </font><br></div>
<div align="center" style="margin:20px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">
<div style="padding-top:10px; font-size:15px;">
<!--Form to post the contents --> //要发布内容的表单
<form action="" name="form1" method="post">
<div style="margin-top:15px; height:30px;">User Name :
<input type="text" name="uname" value=""/> </div>
<div> New Password :
<input type="text" name="passwd" value=""/></div></br>
<div style=" margin-top:9px;margin-left:90px;"><input type="submit" name="submit" value="Submit" /></div>
</form>
</div>
</div>
<div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">
<font size="6" color="#FFFF00">
<?php
//including the Mysql connect parameters. //包含mysql connect参数
include("../sql-connections/sql-connect.php");
error_reporting(0); //关闭错误报告
function check_input($value) //定义check_input函数
{
if(!empty($value)) //如果值不为空,那么执行下面函数
{
// truncation (see comments) //截断获取到的值
$value = substr($value,0,15); //截取value的0-15位的值
}
// Stripslashes if magic quotes enabled //如果魔术引号开启那么就用stripslashes函数
if (get_magic_quotes_gpc()) //如果当 magic_quotes_gpc (用来判断是否为用户提供的数据增加斜线了)打开时,所有的 ' (单引号), " (双引号), (反斜线) and 空字符会自动转为含有反斜线的溢出字符。
{
$value = stripslashes($value); //去除反斜杠
}
// Quote if not a number //如果不是数字那么就加引号
if (!ctype_digit($value)) //ctype_digit:检测是否都是数字,负数及小数都不行,也就是说如果不为数字,为负数或者小数的执行下列代码
{
$value = "'" . mysql_real_escape_string($value) . "'"; //value = '被成功转义的字符串' (转义字符包括 \x00 \n \r \ ' " \x1a)
} //mysql_real_escape_string函数相当于把你输入的字符串仅仅当作字符串来看待,防止改变原有SQL语句
else
{
$value = intval($value); //获取value的整数
}
return $value; //返回value值
}
// take the variables //获取变量
if(isset($_POST['uname']) && isset($_POST['passwd'])) //判断是否获取到了uname和passwd值
{
//making sure uname is not injectable //确保uname是无法注入的
$uname=check_input($_POST['uname']); //给获取到的uname变量执行check_input函数
$passwd=$_POST['passwd']; //passwd变量直接取获取到的值,并未收保护
//logging the connection parameters to a file for analysis. //将连接参数记录到文件中进行分析。
$fp=fopen('result.txt','a'); //用写入权限打开result.txt文件,如果没有该文件就创建
fwrite($fp,'User Name:'.$uname."\n"); //在result.txt文件中写入 User Name:$uname 然后换行
fwrite($fp,'New Password:'.$passwd."\n"); //在result.txt文件中写入New Password: $passwd 然后换行
fclose($fp); //关闭文件result.txt
// connectivity //连接数据库
@$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1"; //定义自己的变量sql
$result=mysql_query($sql); //定义result //mysql_query表示执行这条sql语句
$row = mysql_fetch_array($result); //根据result的结果产生新的数组
//echo $row;
if($row) //如果row存在的话
{
//echo '<font color= "#0000ff">';
$row1 = $row['username']; //产生新的数组row1= row[username]
//echo 'Your Login name:'. $row1;
$update="UPDATE users SET password = '$passwd' WHERE username='$row1'"; //定义更新密码语句$update
mysql_query($update); //执行$update的sql语句
echo "<br>";
if (mysql_error()) //如果执行sql语句报错
{
echo '<font color= "#FFFF00" font size = 3 >';
print_r(mysql_error()); //打印变量,用更利于理解的方式打印
echo "</br></br>";
echo "</font>";
}
else //如果不报错
{
echo '<font color= "#FFFF00" font size = 3 >';
//echo " You password has been successfully updated " ;
echo "<br>";
echo "</font>";
}
echo '<img src="../images/flag1.jpg" />'; //输出flag1.jpg这个图片
//echo 'Your Password:' .$row['password'];
echo "</font>";
}
else //其他情况的话
{
echo '<font size="4.5" color="#FFFF00">';
//echo "Bug off you Silly Dumb hacker";
echo "</br>";
echo '<img src="../images/slap1.jpg" />'; //输出图片slap1.jpg
echo "</font>";
}
}
?>
</font>
</div>
</body>
</html>