$part_id=$_POST["part_id"];
$password=trim($_POST["password"]);
$user_id=trim($_POST["user_id"]);
$conn=mysql_connect("localhost:3306","","") or die('failed');
mysql_select_db("softedit") or die('selectfailed');
$query_user="select * from user where user_id='$user_id' and part_id='$part_id'";
$result_user=mysql_query($query_user);
$row_user=mysql_fetch_array($result_user);
if(!$row_user)
{
mysql_close();
echo "<script>alert('无此用户!');history.back();</script>";
}
else
{
$query_password="select * from user where user_id='$user_id' and part_id='$part_id' and pwd=password('$password')";
$result_password=mysql_query($query_password);
if(!$row=mysql_fetch_array($result_password))
{
mysql_close();
echo "<script>alert('密码不正确');history.back();</script>";
}
else
{
header("Location:index.php");//验证通过
}
}
$password=trim($_POST["password"]);
$user_id=trim($_POST["user_id"]);
$conn=mysql_connect("localhost:3306","","") or die('failed');
mysql_select_db("softedit") or die('selectfailed');
$query_user="select * from user where user_id='$user_id' and part_id='$part_id'";
$result_user=mysql_query($query_user);
$row_user=mysql_fetch_array($result_user);
if(!$row_user)
{
mysql_close();
echo "<script>alert('无此用户!');history.back();</script>";
}
else
{
$query_password="select * from user where user_id='$user_id' and part_id='$part_id' and pwd=password('$password')";
$result_password=mysql_query($query_password);
if(!$row=mysql_fetch_array($result_password))
{
mysql_close();
echo "<script>alert('密码不正确');history.back();</script>";
}
else
{
header("Location:index.php");//验证通过
}
}
$myrow = mysql_num_rows($result);
if($myrow!='1')
{
//身份验证不成功,提示用户重新输入
echo "<p>";
echo "<center>很抱歉,你输入的用户名错误,请<a href=index.php><font color=red>返回</font></a>重输!";
}
else {
//以下为身份验证成功后的相关操作
echo "<p>";
echo "<center>恭喜你,登录成功!";
} 这也许是最短的验证了吧,在你的基础上改的,很不安全,有空再给你写吧,
$result_user=mysql_query($query_user);
$row_user=mysql_fetch_array($result_user);
if(!$row_user)
{
mysql_close();
echo "<script>alert('无此用户!');history.back();</script>";
}
else
{
$query_password="select * from dbuser where password='$password'";
$result_password=mysql_query($query_password);
if(!$row=mysql_fetch_array($result_password))
{
mysql_close();
echo "<script>alert('密码不正确');history.back();</script>";
}
else
{
header("location:member.php"); //验证通过
}
}
这是我根据kxyes网友所写的代码改写的,但没有完全成功运行,如果用户名或密码输入不正确,那会正确执行语句,但如果用户名及密码都正确无误时就出现问题了,无法重定向到指定页面,出现提示说header("localtion:member.php");这一行错误,但这个语句本身并没有错啊!只是我不明白在php中并没有if else else这样的语句,是不是这个错误呢?但如果我把这个重定向语句改为echo "验证通过!"这样的语句,却又是运行无误,还请大家再给指点一二好吗?个中原因不明白。
而且我对kxyes网友所提供的语句中采用and连接查询的方法不太认同,我在asp中从来不用这种方法验证,这种语法存在or漏洞,不知我的看法是对是错?
最后感谢楼上二位的指点,还请大家能再一步指点我,谢谢。
你是写错了
location