<?php
error_reporting(0);
ini_set("date.timezone","PRC");
require_once("config.php");
isset($_POST['username'])?$username=$_POST['username']:$username=null;
isset($_POST['userpass'])?$userpass=$_POST['userpass']:$userpass=null;
isset($_POST['nicheng'])?$nicheng=$_POST['nicheng']:$nicheng=null;
isset($_POST['union'])?$union=$_POST['union']:$union="0";
$sql = "select * from dunling_menber where username='$username'";
$ery = mysql_query($sql,$config);
$num = mysql_num_rows($ery);
if($num >= "1"){
    echo '1';
    exit;
}
$regtime = time();
$userpass = sha1($userpass."www.dunling.com");
$sql = "insert into dunling_menber (username,userpass,nicheng,moneypay,money,regtime,logintime,unions,kl) values ('$username','$userpass','$nicheng','1.00','1.00','$regtime','$regtime','$union','10')";
$ery = mysql_query($sql,$config)or die(mysql_error());
if($union >= "1"){
    $upsql = "update dunling_menber set unions_num=unions_num+'1' where id = '$union' ";
    mysql_query($upsql,$config);
}


if($ery){
    echo 'ok';
    $sql = "select * from dunling_menber where username='$username'";
    $ery = mysql_query($sql,$config);
    $u = mysql_fetch_array($ery);
    $uid = $u['id'];
    $nicheng = $u['nicheng'];
    $username = $u['username'];
    setcookie("uid",$uid,time()+3600*24,'/');//COOKIE有效期一年;
    setcookie("nicheng",$nicheng,time()+3600*24,'/');//COOKIE有效期一年;
    setcookie("username",$username,time()+3600*24,'/');//COOKIE有效期一年;
    exit;
}
mysql_close();
?>