<?php  
	
	// session开始  
    session_start();  
	
    $name = $_POST['name'];   
    $password = $_POST['password'];  
	
	$_SESSION['name'] = "wanhua";
	$_SESSION['password'] = "wanhua";

if(checkname($name)){
    if(checkpassword($password)){
            setcookie("password",md5($password),time()+3600*24*3);
			header("location: index.php ");            //全部验证都通过之后跳转到首页
        }
		else{
			unset($_SESSION['username']);
            setcookie("username","",time()-1);   //清空cookie
            setcookie("password","",time()-1);
            } 
	}
 
//方法：检查用户名
function checkname($name){
    if($name == $_SESSION['name']){
        return true;
    }
    else{
       echo '<html><head><Script Language="JavaScript">alert("用户名或密码错误");</Script></head></html>' . "<meta http-equiv=\"refresh\" content=\"0;url=login.php\">";
    }
}
 
//方法：检查密码
function checkpassword($password){
    if($password == $_SESSION['password']){
        return true;
    }
    else{
       echo '<html><head><Script Language="JavaScript">alert("用户名或密码错误");</Script></head></html>' . "<meta http-equiv=\"refresh\" content=\"0;url=login.php\">";
    }
}
		?> 
