<?PHP
require_once 'db.php';
session_start();
if($_POST[textfield3]<>$_SESSION['VCODE'] ){
echo("验证码不正确");
exit();
} 
$_SESSION['VCODE'] =rand(999,9999);
if($_POST[button2]){
$sql="SELECT * FROM `gm_user` where (`user` = '".$_POST[textfield]."') ";
$query=$db->query($sql);
$userdata= $db->fetch_array($query);
if($userdata[pass]==md5($_POST[textfield2])){
setcookie("zhanghao", $_POST[textfield], time() + 60*60*24*30*12);
setcookie("mima",md5($_POST[textfield2]), time() + 60*60*24*30*12);
echo("登录成功");
} 
} 
if($_POST[button]){
$sql="SELECT * FROM `gm_user` where (`user` = '".$_POST[textfield]."') ";
$query=$db->query($sql);
$userif= $db->fetch_array($query);
if($userif[id]<>null){
echo("此账号已经被注册");
}else{
$sql="INSERT INTO `gm_user` (`id`,`user`,`pass`,`ip`) VALUES (NULL,'".$_POST[textfield]."','".md5($_POST[textfield2])."','".$_SERVER["REMOTE_ADDR"]."') ";
$db->query($sql);
setcookie("zhanghao", $_POST[textfield], time() + 60*60*24*30*12);
setcookie("mima",md5($_POST[textfield2]), time() + 60*60*24*30*12);
echo("注册成功");
} 

} 
?>