php怎样过滤非法字符防止sql注入? 5
if($_POST["Submit"]){$username=$_POST["username"];$pwd=$_POST["pwd"];$code=$_POST["co...
if($_POST["Submit"])
{
$username=$_POST["username"];
$pwd=$_POST["pwd"];
$code=$_POST["code"];
if($code<>$_SESSION["auth"])
{
echo "<script language=javascript>alert('验证码不正确!');window.location='login.php'</script>";
?>
<?php
die();
}
$sql="select * from admin where username='$username' and password='$pwd'";
$rs=mysql_query($sql);
if(mysql_num_rows($rs)==1)
{
$_SESSION["pwd"]=$_POST["pwd"];
$_SESSION["admin"]=session_id();
echo "<script language=javascript>alert('登陆成功!');window.location='admin_index.php'</script>";
}
else
{
echo "<script language=javascript>alert('用户名或密码错误!');window.location='login.php'</script>";
?>
<?php
die();
}
}
?>
上面php代码怎样修改,过滤用户输入的非法字符防止sql注入??? 展开
{
$username=$_POST["username"];
$pwd=$_POST["pwd"];
$code=$_POST["code"];
if($code<>$_SESSION["auth"])
{
echo "<script language=javascript>alert('验证码不正确!');window.location='login.php'</script>";
?>
<?php
die();
}
$sql="select * from admin where username='$username' and password='$pwd'";
$rs=mysql_query($sql);
if(mysql_num_rows($rs)==1)
{
$_SESSION["pwd"]=$_POST["pwd"];
$_SESSION["admin"]=session_id();
echo "<script language=javascript>alert('登陆成功!');window.location='admin_index.php'</script>";
}
else
{
echo "<script language=javascript>alert('用户名或密码错误!');window.location='login.php'</script>";
?>
<?php
die();
}
}
?>
上面php代码怎样修改,过滤用户输入的非法字符防止sql注入??? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询