这样试试,前提是你要把注销的代码改称如下。
注销的代码是:
logout.php
<?
setcookie("reg_nicker","");//清空
setcookie("reg_password","");//清空
?><?
include("db_mysql.inc");
$db= new db_sql;
$db->connect("borrow","localhost","root","");
//$nicker,$password,是用户登录时注册的cookie,
//$level是用户的级别,0是普通用户,1是管理员。
//
function check_user($nicker,$password,$level=2)
{
 global $db;
 if(is_null($nicker))
  return 0;
 switch ($level)
 {
  case 1:
  $sql = "select password from user_info where nicker='$nicker' and level='$level'";
  break;
  case 0:
  $sql = "select password from user_info where nicker='$nicker' and level='$level'";
  break;
  default:
  $sql = "select password from user_info where nicker='$nicker'";
 }
 $db->query($sql);
 $db->records();
 if(md5($db->get('password')) == $password)
    return 1;
 else
    return 0;
}
?>

解决方案 »

  1.   

    我试了可以,但我不明白的是我用
    setcookie("reg_nicker")
    setcookie("reg_password")
    进行注销怎么不行呢?
    我看到书上介绍,删除cookie是这样的呀,难道是最新版本惹的祸?
    再就是我的这个认证函数严密吗?
      

  2.   


        不知道你在传入参数时是否了检查参数合法性。如果没有,应该再做一个参数处理模块check($para),检查参数合法性。因为当参数中含有非法字符时,用其调用数据库很危险。如果参数
        $nicker = 'aa\' or 1=1 ';
    则查询的结果就会出错,但这样做多数可能是恶意的,当
      $nicker = 'aa\'; delete from user_info where 1=1 ';
    这时下面的语句被展开后应该是:展开前:
       select password from user_info where nicker='$nicker' and level='$level'
    展开后:
       select password from user_info where nicker='aa';
          delete from user_info where 1=1 and level=0';看出来了吧,这样数据库被攻击了。
        PHP的弱点不在于语言本身,而是编程的处理问题.安全漏洞往往是由于编程时的疏忽造成的
      

  3.   

    安全起间,应该将原有cookie清空。
      

  4.   

    在传入之前我做了数据和发行检查。
    zjingwei(深海之舟) 的建议不错。谢谢!