<?php
require ('authentication_member.php');
?>
<?php

/* 运行登陆 */
/* 162100源码 - 162100.com */

@ require ('inc/set/set_userface.php');
@ require ('inc/function/img.php');
@ require ('inc/function/write_file.php');
if (!function_exists('read_file')) {
  @ require ('inc/function/read_file.php');
}
require ('inc/function/filter.php');

$key = $_POST['key'];
$bar_face = $_POST['bar_face'];

/* 用户名|积分|权限|上次登陆时间|key|cookie时效 */
$_POST = array_map('tirm_all', $_POST);
if (!$_GET['location'] = $_GET['location']) {
  $_GET['location'] = $_POST['location'];
}

$_GET['location'] = !empty($_GET['location']) ? $_GET['location'] : $_SERVER['HTTP_REFERER'];
$loc = preg_replace('/^'.preg_quote($web['path'], '/').'/i', '', $_GET['location']);
$loc = empty($loc) ? 'index.php' : $loc;
//$loc = file_exists(preg_replace('/(\?|#).*$/', '', $loc)) ? $loc : 'index.php';
$date = gmdate("Y-m-d H:i:s", time() + (floatval($web["time_pos"]) * 3600));
if ($_POST['save_cookie']!=31536000) {
  $_POST['save_cookie'] = 0;
}
$cookie_time = time() + floatval($web['time_pos']) * 3600 + $_POST['save_cookie'];

//退出
if ($_GET['act'] == 'logout') {
  @ setcookie('usercookie', '', time() - 666 * 60 * 60, '/', '.'.$web['root']);
  @ setcookie('usercookie', '', time() - 666 * 60 * 60, '/');

  if ($_GET['m'] == 1) {
    err('<script>
try{parent.loginReload();}catch(e){} var pS=parent.$("session_online");if(pS!=null){pS.innerHTML="<span id=\"session_in\" class=\"session_in\"><a href=\"login.php\" onmouseover=\"showLogin(this,\'session_in\');\">登陆您的帐号</a> | <a href=\"reg.php\">免费注册帐号</a></span>";}
/*
function isexitsfunction(funcname) {
    try {
        if (typeof(eval(funcname)) == "function") {
            return true;
        }
    } catch(e) {}
    return false;
}
if(isexitsfunction(parent.confirmLogin)) {
  parent.confirmLogin();
}
*/

</script>');
  }
  alert('注销成功，欢迎再来', !empty($loc) ? $loc : (!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : './'));

//登陆
} elseif ($_POST['act'] == 'login') {
  $js_say = '<script>
window.onload=function(){
  var par=parent.document.getElementById("addCFrame");
  if(par!=null){
    try{
      par.style.height=$("transition").offsetHeight+"px";
    }catch(err){
    }
  }
}
</script>
';
  $js_say2 = '<script language="javascript" type="text/javascript">
var eIs=false;
var sIs=false;
  if (parent.document.getElementById("f_c162100_tool")!=null){
    var eIs=true;
  }
  </script>
<script language="javascript" type="text/javascript">
  var pS=parent.document.getElementById("session_online");
  if(pS!=null){
    var sIs=true;
    try{parent.loginReload();}catch(e){}
  }

  var pI=parent.$("addCFrame");
  if(pI!=null){
    pI.style.display="none";
  }
  var pF=parent.$("fexpires");
  if(pF!=null){
    try{pF.style.display="none";}catch(e){}
  }
  if(eIs==true){
try{parent.document.getElementById("f_c162100_tool").innerHTML=parent.addTools(parent.eX);}catch(e){}
  }
</script>
';

  if (empty($_POST['username'])) {
    err('提交被拒绝！用户名不能空！');
  }
  /*
  if (empty($_POST['password']) || !preg_match('/^[^\s\\\]{3,30}$/', $_POST['password'])) {
    err('提交被拒绝！密码——长度请控制在3-30个字符之内。不能有空格和 \ 。');
  }
  */
  if (empty($_POST['password']) || !preg_match('/^.{3,30}$/', $_POST['password'])) {
    err('提交被拒绝！密码——长度请控制在3-30个字符之内。');
  }
  if (isset($_COOKIE['usercookie'])) {
    /*
    $session = @explode('|', $_COOKIE['usercookie']);
    err('您已经以 用户名：'.$session[0].' 登陆过了！<br />要想更换用户名登陆，请先<a href="member.php?post=login&act=logout&location=login.php">退出</a>。');
    */
    if (empty($_POST['imcode']) || !is_numeric($_POST['imcode']))
      err('必须准确填写数字验证码！<span class="grayword">（如看不到验证码，请返回刷新页面）</span>');
    if ($_POST['imcode'] != $_COOKIE['regimcode'])
      err('验证码不符！<span class="grayword">（如看不到验证码，请返回刷新页面）</span>');
  }

  if (!isset($sql['db_err'])) {
    db_conn();
  }
  if ($sql['db_err'] == '') {

    $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.str_replace('.', '&#46;', $_POST['username']).'" OR email="'.$_POST['username'].'" LIMIT 1', $db);
    $row = @mysql_fetch_assoc($result);
    @mysql_free_result($result);
    if (is_array($row) && count($row) > 0) {
      if (/*$web['stop_reg'] == 2 && */$row['check_reg'] == '1') {
        err('您的注册尚未通过审批！无法登陆。');
      }
      if ($row['check_reg'] == '2') {
        err('您的帐户已被管理员移除至<a href="list_member.php?act=punished" target="_blank">黑名单</a>。');
      }
	  if($row['password'] == md162100($_POST['password'])){
        if ($row['power'] != 'm' && substr($row['thisdate'], 0, 10) != substr($date, 0, 10)) {
          $row_point = 'point=point+'.abs($web['loginadd']).',';
          $row['point'] = $row['point'] + abs($web['loginadd']);
        }
	    $you = array(
          'name'  => $row['username'],
	      'key'   => $date.'|'.s_rand(16),
          'point' => $row['point'],
          'power' => $row['power'],
        );
        if ($you['name'] == $web['manager']) {
          if (!file_exists('__temp__/temp')) {
	        if (!@mkdir('__temp__/temp', 0777)) {
              err('上载目录__temp__/temp不存在或创建失败！请稍候重新登录再试。');
            }
          }
          write_file('__temp__/temp/'.urlencode($you['name']).'.php', '<?php die(); ?>'.$you['key'].''); //登录密钥记录
        }
/*
<script>
var expiration=new Date(new Date().getTime()+8*3600*1000);
document.write(expiration.toUTCString());
</script>
<?php
echo gmdate('D, d M Y H:i:s T', time() + floatval($web['time_pos']) * 3600);
?>
*/

  
		
        setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], $cookie_time, '/', '.'.$web['root']);
        setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], $cookie_time, '/');
    if ($row['power'] != 'm') {
      if (!preg_match('/^(\(\d+\-\d+\))+$/', $row['power'])) {
        $power = 1; //会员
      } else {
        $power = 2; //版主
      }
    } else {
      if ($you['name'] == $web['manager']) {
        $power = 5; //基础管理员
      } else {
        $power = 4; //管理员
      }
    }


        //判断列session_key是否存在，不存在创建
        //$result_session = @mysql_query('SELECT session_key FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.$web['manager'].'"', $db);
        //$row_session = @mysql_fetch_assoc($result_session);
        //if (!isset($row_session['session_key'])) {
          @mysql_query('ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` ADD COLUMN `session_key` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ""');
        //}
        //@mysql_free_result($result_session);



        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET '.$row_point.'thisdate="'.$date.'",session_key="'.$you['key'].'" WHERE username="'.$row['username'].'" LIMIT 1', $db); //更新最后访问时间
        /*确认头像存在否*/
        //$web['img_name_b'] = '162100userface_'.urlencode($you['name']);
        $yougourl = '<table width="100%" border="0" cellspacing="10" cellpadding="0" class="wherego"><tr>';
        if ($you['power'] == 'm') {
          $yougourl .= '<td class="whereyou">您是管理员，您可以选择去向：</td><td align="left"><ul><li><a href="webmaster_central.php">管理后台</a></li><li><a href="member.php">用户中心</a></li><li><a href="write.php">发布文章</a></li><li><a href="'.$loc.'">'.$loc.'</a></li></ul></td>';
        } elseif (preg_match('/^(\(\d+\-\d+\))+$/', $you['power'])) {
          $yougourl .= '<td class="whereyou">您是版主，您可以选择去向：</td><td align="left"><ul><li><a href="webmaster_central.php">管理后台</a></li><li><a href="member.php">用户中心</a></li><li><a href="write.php">发布文章</a></li><li><a href="'.$loc.'">'.$loc.'</a></li></ul></td>';
        } else {
          $yougourl .= '<td class="whereyou">您可以选择去向：</td><td align="left"><ul><li><a href="./">首页</a></li><li><a href="member.php">用户中心</a></li><li><a href="write.php">发布文章</a></li><li><a href="'.$loc.'">'.$loc.'</a></li></ul></td>';
        }
        $yougourl .= '</tr>
</table>';
        $yougourl .= empty($row['company']) ? '<div class="redword">提示：您还没有添加商号！建议你到用户中心完善</div>' : '';


  if ($_POST['m'] == 1) {
    err($js_say2.'
<script language="javascript" type="text/javascript">
  if(sIs==true){
try{pS.innerHTML=\'<b>'.$you['name'].'</b> '.user_class($power, $row['point']).' | <a href="member.php">用户中心</a> | <a href="member.php?post=login&act=logout&m=1" onclick="return logoutM(this);">退出</a> | <span id="fw">您上次登陆是'.$row['thisdate'].'</span>\';}catch(e){}
  }
  </script>');
  }




        if (!(@mysql_num_rows(@mysql_query('SELECT id FROM `'.$sql['pref'].''.$sql['data']['承载上传数据的表名'].'` WHERE title LIKE "face-'.$you['name'].'.%"', $db)) > 0)) {
          err('登陆成功！欢迎您 '.$you['name'].'。'.$yougourl.'<script>'.($web['send_face'] == 1 ? 'alert("注册成员必须上传了头像才允许发表，请上传");location.href="member.php";' : 'location.href=confirm("您还没有Logo/头像，是否制作一个？只需半分钟——")?"member.php":"'.$loc.'"').'</script>。', 'ok');
        } else {
          alert('登陆成功！欢迎您 '.$you['name'].'。'.$yougourl, $loc);
        }
	  } else {
        if (is_numeric($web['stop_login']) && $web['stop_login'] > 0 && $row['username'] != $web['manager']) {
          if (substr($row['thisdate'], 0, 10) == substr($date, 0, 10)) { //当天
            $stop_add = abs($row['stop_login'])+1;
          } else {
            $stop_add = 1;
          }
          @mysql_query('ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` ADD COLUMN `stop_login` int(2) NOT NULL DEFAULT "0"');
//err(mysql_errno().':'.mysql_error());
          @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET thisdate="'.$date.'",stop_login="'.$stop_add.'" WHERE username="'.$row['username'].'" LIMIT 1', $db);
          $s_l_s = '<br />您已经'.$stop_add.'次输错密码。今天还剩'.($web['stop_login'] - $stop_add).'次登录机会';
        }

        if ($_POST['username'] != $web['manager']) {
          err('密码不符！'.$s_l_s);
        } else {
          base_manager_login();
        }
	  }
    } else {
      if ($_POST['username'] != $web['manager']) {
        err('登陆失败！原因：1、用户尚未注册；2、表连接不成功或尚未建立！');
      } else {
        base_manager_login(1);
      }
	}
    @mysql_close();
  } else {
    base_manager_login();
  }






//找回密码
} elseif ($_POST['act'] == 'foundpassword') {
  if ($_POST['type']!='question' && $_POST['type']!='mail') {
    err('找回方式有误！');
  }
  if ($session[0] == $web['manager'] || $session[4] == 'm' || $_POST['username'] == $web['manager']) {
    err('禁止以管理员名义进行此项！');
  }

  if (!isset($sql['db_err'])) {
    db_conn();
  }
  if ($sql['db_err'] != '') {
    err($sql['db_err']);
  }

  $new_password=strtolower(s_rand(8));
  $new_password_encode=md162100($new_password);
  if ($_POST['type']=='question') :

    if ($_POST['password_question'] == '') {
      err('密码问题不能留空！');
    }
    if ($_POST['password_answer'] == ''){
      err('密码答案不能留空！');
    }
    if (empty($_COOKIE['regimcode'])) {
      err('不能没有验证码！请检测你的浏览器，确保cookie未禁用。<span class="grayword">（如看不到验证码，请返回刷新页面）</span>');
    }
    if (empty($_POST['imcode']) || !is_numeric($_POST['imcode']))
      err('验证码非数字！<span class="grayword">（如看不到验证码，请返回刷新页面）</span>');
    if ($_POST['imcode'] != $_COOKIE['regimcode'])
      err('验证码不符！<span class="grayword">（如看不到验证码，请返回刷新页面）</span>');
	
    $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.str_replace('.', '&#46;', $_POST['username']).'" OR email="'.$_POST['username'].'" LIMIT 1', $db);
    $row = @mysql_fetch_assoc($result);
    @mysql_free_result($result);
    if (is_array($row) && count($row) > 0) {
      if ($row['username'] == $web['manager']) {
        err('禁止以管理员名义进行此项！管理员修改密码请到后台“基本参数管理”');
      }
      if ($row['check_reg'] == 1) {
        err('注册审核中！');
      } elseif ($row['check_reg'] == 2) {
        err('你已被置入黑名单！');
      } else {
        if (is_numeric($web['stop_login']) && $web['stop_login'] > 0) {
          $stop_num = abs($row['stop_login']);
          if (is_numeric($stop_num) && $stop_num >= $web['stop_login'] && substr($row['thisdate'], 0, 10) == substr($date, 0, 10)) {
            err('找回密码系统只允许执行'.$stop_num.'次！你今天找回密码（含登录时密码输错）已超过此限，无法再执行。');
          }
        }
        if (is_numeric($web['stop_login']) && $web['stop_login'] > 0) {
          if (substr($row['thisdate'], 0, 10) == substr($date, 0, 10)) { //当天
            $stop_add = abs($row['stop_login'])+1;
          } else {
            $stop_add = 1;
          }
          $evfor=',thisdate="'.$date.'",stop_login="'.$stop_add.'"';
          $s_l_s = '<br />您已经'.$stop_add.'次找回密码。今天还剩'.($web['stop_login'] - $stop_add).'次找回（含登录）机会';
        }
		
	    if ($row['password_question'] != $_POST['password_question']) {
	      err('密码问题与注册时所填不符！'.$s_l_s.'');
        } elseif ($row['password_answer'] != $_POST['password_answer']) {
	      err('密码答案不对！'.$s_l_s.'');
        } else {
          @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET password="'.$new_password_encode.'"'.$evfor.' WHERE id="'.$row['id'].'"', $db);
          err('找到密码成功！已为你重置了新密码：'.$new_password.'——请前往<a href="login.php">登陆</a>。', 'ok');
        }
	  }
    } else {
      err('出错！数据库查无此帐号！请稍候再试');
    }

  elseif ($_POST['type']=='mail') :
    $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE email="'.$_POST['username'].'" LIMIT 1', $db);
    $row = @mysql_fetch_assoc($result);
    @mysql_free_result($result);
    if (is_array($row) && count($row) > 0) {
      if ($row['username'] == $web['manager']) {
        err('禁止以管理员名义进行此项！管理员修改密码请到后台“基本参数管理”');
      }
      if ($row['check_reg'] == 1) {
        err('注册审核中！');
      } elseif ($row['check_reg'] == 2) {
        err('你已被置入黑名单！');
      } else {
        if (is_numeric($web['stop_login']) && $web['stop_login'] > 0) {
          $stop_num = abs($row['stop_login']);
          if (is_numeric($stop_num) && $stop_num >= $web['stop_login'] && substr($row['thisdate'], 0, 10) == substr($date, 0, 10)) {
            err('找回密码系统只允许执行'.$stop_num.'次！你今天找回密码（含登录时密码输错）已超过此限，无法再执行。');
          }
        }
        if (is_numeric($web['stop_login']) && $web['stop_login'] > 0) {
          if (substr($row['thisdate'], 0, 10) == substr($date, 0, 10)) { //当天
            $stop_add = abs($row['stop_login'])+1;
          } else {
            $stop_add = 1;
          }
          $evfor=',thisdate="'.$date.'",stop_login="'.$stop_add.'"';
          $s_l_s = '<br />您已经'.$stop_add.'次找回密码。今天还剩'.($web['stop_login'] - $stop_add).'次找回（含登录）机会';
        }
        require_once ('inc/function/mail_class.php');
        $subject = "找回密码[".$web["sitename"]."]";
        $subject = "=?UTF-8?B?".base64_encode($subject)."?="; //此行解决utf-8编码邮件标题乱码
        $body = '你好！<br />
　    　你在['.$web["sitename"].']进行找回密码，新的密码为：'.$new_password.'<br />请点此链接<a href="'.$web['path'].'login.php" target="_blank">'.$web['path'].'login.php</a>登录。';
        $to = $row['email']; //收件人 
        $send = $smtp -> sendmail($to, $web['sender'], $subject, $body, $web['mailtype']);
        if ($send != 1) {
          err('系统尝试连接您的邮箱['.$to.']并发送失败！原因：可能是您所填写的邮箱无效。请仔细填写并检查，或返回重试。如有疑问可<a href="list.php?area_id=96" target="_blank">站内留言</a>。'.$s_l_s.'');
        }
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET password="'.$new_password_encode.'"'.$evfor.' WHERE id="'.$row['id'].'"', $db);
        err('密码已发往你的邮箱。请前往你的邮箱查看。', 'ok');
	  }
    } else {
      err('出错！数据库查无此帐号！请稍候再试');
    }
  endif;

  @mysql_close();

//绑定
} elseif ($_POST['act'] == 'tie') {

  if ($_POST['bar'] == 'qq') {
    if (!$key || strlen($key) != 64) {
      err('参数key缺失或错误！');
    }
  } elseif ($_POST['bar'] == 'weibo') {
    if (!$key || strlen($key) != 10) {
      err('参数key缺失或错误！');
    }
  } elseif ($_POST['bar'] == 'baidu') {
    if (!$key) {
      err('参数key缺失或错误！');
    }
 //
  } elseif ($_POST['bar'] == '162100') {
    if (!$key) {
      err('参数key缺失或错误！');
    }
 //
  } else {
    err('参数bar缺失或错误！');
  }


  if (empty($_POST['username'])) {
    err('提交被拒绝！用户名不能空！');
  }
  if (empty($_POST['password']) || !preg_match('/^.{3,30}$/', $_POST['password'])) {
    err('提交被拒绝！密码长度3-30个字符之内。');
  }

  if (!isset($sql['db_err'])) {
    db_conn();
  }
  if ($sql['db_err'] != '') {
    err($sql['db_err']);
  }

  @mysql_query('ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` ADD COLUMN `login_key_'.$_POST['bar'].'` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ""');

  $result = @mysql_query('SELECT COUNT(id) AS n FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE login_key_'.$_POST['bar'].'="'.$key.'"', $db);
  $row = @mysql_fetch_assoc($result);
  @mysql_free_result($result);
  if ($row['n'] > 0) {
    err('已经绑定过了！请先解除已存在的['.$_POST['bar'].']绑定。');
  }
  unset($row);

  $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.str_replace('.', '&#46;', $_POST['username']).'" OR email="'.$_POST['username'].'"', $db);
  $row = @mysql_fetch_assoc($result);
  @mysql_free_result($result);

  if (is_array($row) && count($row) > 0) {
    if (/*$web['stop_reg'] == 2 && */$row['check_reg'] == '1') {
      err('用户 '.$_POST['username'].' 的注册尚未通过审批！无法绑定。');
    }
    if ($row['check_reg'] == '2') {
      err('用户 '.$_POST['username'].' 已被移除至黑名单。');
    }

    if($row['password'] == md162100($_POST['password'])){
      $you = array(
          'name'  => $row['username'],
	      'key'   => $date.'|'.s_rand(16),
          'point' => $row['point'],
          'power' => $row['power'],
      );
      if ($you['name'] == $web['manager']) {
	  /*
        if (!file_exists('__temp__/temp')) {
	      if (!@mkdir('__temp__/temp', 0777)) {
            err('上载目录__temp__/temp不存在或创建失败！请稍候重新登陆再试。');
          }
        }
		*/
        write_file('__temp__/temp/'.urlencode($you['name']).'.php', '<?php err(); ?>'.$you['key'].''); //登陆密钥记录
      }

      @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET thisdate="'.$date.'",session_key="'.$you['key'].'",login_key_'.$_POST['bar'].'="'.$key.'" WHERE username="'.$row['username'].'" LIMIT 1', $db);//


        setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], $cookie_time, '/', '.'.$web['root']);
        setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], $cookie_time, '/');

        $yougourl = '<table width="100%" border="0" cellspacing="10" cellpadding="0" class="wherego"><tr>';
        $yougourl .= '<td class="whereyou">您可以选择去向：</td><td align="left"><ul><li><a href="./" target="_parent">首页</a></li>'.($you['name'] == $web['manager'] ? '<li><a href="webmaster_central.php" target="_parent">管理员中心</a></li>' : '').'<li><a href="member.php" target="_parent">用户中心</a></li><li><a href="'.$loc.'">先前页面：'.$loc.'</a></li></ul></td>';
        $yougourl .= '</tr>
</table>';


      alert('<span style="line-height:16px">绑定成功！欢迎您 '.$you['name'].''. $yougourl.''.$err.'</span>', $loc);



    } else {
      err('密码不符！');
    }
  } else {
    err('查无帐号！');
  }
  @mysql_close();






//新建
} elseif ($_POST['act'] == 'new') {


  if ($_POST['bar'] == 'qq') {
    if (!$key || strlen($key) != 64) {
      err('参数key缺失或错误！');
    }
  } elseif ($_POST['bar'] == 'weibo') {
    if (!$key || strlen($key) != 10) {
      err('参数key缺失或错误！');
    }
  } elseif ($_POST['bar'] == 'baidu') {
    if (!$key) {
      err('参数key缺失或错误！');
    }
 //
  } elseif ($_POST['bar'] == '162100') {
    if (!$key) {
      err('参数key缺失或错误！');
    }
 //
  } else {
    err('参数bar缺失或错误！');
  }

  if ($web['stop_reg'] == 1) {
    err('当前系统设置为：禁止新用户注册。');
  } elseif ($web['stop_reg'] == 2) {
    $check1 = ',`check_reg`';
    $check2 = ',"1"';
    $check3 = '（此次注册需要审批，请耐心等待）。';
  } else {
    //$check3 = '请保持持续热情支持['.$web['sitename'].']，并欢迎积极发表、反馈问题。';
  }

  if (empty($_POST['username'])) {
    err('提交被拒绝！用户名不能空！');
  }
  if (strlen($_POST['username']) < 3 || strlen($_POST['username']) > 45) {
    err('提交被拒绝！用户名长度范围为3-45字符！');
  }
  if (preg_match('/admin|manager|管理员|版主|斑竹|访客|系统欢迎信|162100|furuijinzhao|操|temp|info|mess|mail|请输入用户名/i', $_POST['username'], $matches)) {
    err('提交被拒绝！用户名中含'.$matches[0].'，未获通过。');
  }

  $_POST['username'] = str_replace('.', '&#46;', $_POST['username']);

  $bar_face_contents = '';
  if ($bar_face != '') {
    if ($bar_face_contents = read_file($bar_face)) {
	  
      //if (!$format = @strtolower(ltrim(strrchr($bar_face, '.'), '.'))) {
	    $img_info = @getimagesize($bar_face);
		$format = @strtolower(ltrim(strrchr($img_info['mime'], '/'), '/'));
		$format = $format == 'jpeg' ? 'jpg' : $format;
	  //}

	  if ($format != $web['img_up_format']) {
	    $temp_img = '__temp__/'.urlencode($_POST['username']).'.'.$format;
	    write_file($temp_img, $bar_face_contents);
	    $temp_img = typeto($temp_img, $web['img_up_format']);
        $bar_face_contents = read_file($temp_img);
		@unlink($temp_img);
	  }
	}
	//$img_info = getimagesize($bar_face);
  }

  if (!isset($sql['db_err'])) {
    db_conn();
  }
  if ($sql['db_err'] != '') {
    err($sql['db_err']);
  }

  if (@mysql_num_rows(@mysql_query('SELECT id FROM `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` WHERE username="'.$_POST['username'].'" OR email="'.$_POST['username'].'"', $db)) > 0) {
    err('此用户名已被注册！');
  }
  if (@mysql_num_rows(@mysql_query('SELECT id FROM `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` WHERE username="'.$_POST['email'].'" OR email="'.$_POST['email'].'"', $db)) > 0) {
    err('此邮箱已有人使用！');
  }

  $check4 = '';

  /*
  发送邮件-------------------
  */
  if ($web['mail_send'] == 1) {
    require_once ('inc/function/mail_class.php');
    $subject = "欢迎注册[".$web["sitename"]."]";
    $subject = "=?UTF-8?B?".base64_encode($subject)."?="; //此行解决utf-8编码邮件标题乱码
    $body = '　　欢迎加入['.$web["sitename"].']！<br />　　'.$check3.'<br />　　我们的站址为：<a href="'.$web['path'].'" target="_blank">'.$web['path'].'</a>，欢迎光临。<br /><br /><br /><br /><font color=#999999>如果不是您本人使用此邮箱进行的注册，您可至<a href="'.$web['path'].'" target="_blank">'.$web['path'].'</a>与管理员取得联系，我们将对冒用您邮箱的用户进行删除。</font>';
    $to = $_POST['email']; //收件人 
    $send = $smtp -> sendmail($to, $web['sender'], $subject, $body, $web['mailtype']);
    if ($send != 1) { 
      err('系统尝试连接您的邮箱['.$to.']并发送失败！原因：可能是您所填写的邮箱无效。请仔细填写并检查，或返回重试。如有疑问可<a href="list.php?area_id=96" target="_blank">站内留言</a>。');
    }
  }
  $messline = "".preg_replace("/[^\d]+/", "", $date)."|".$web['manager']."|欢迎加入".$web["sitename"]."！|欢迎加入！请保持持续热情支持".$web["sitename"]."，并欢迎积极发表、反馈问题。||| \n";
  $session_key = $date.'|'.s_rand(16);

  @mysql_query('ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` ADD COLUMN `session_key` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ""', $db);
  @mysql_query('ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` ADD COLUMN `login_key_'.$_POST['bar'].'` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ""', $db);

  @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` (`username`,`email`,`regdate`,`thisdate`,`company_description`,`mess`,`mess_num`,`session_key`,`login_key_'.$_POST['bar'].'`'.$check1.') values 
("'.$_POST['username'].'","'.$_POST['email'].'","'.$date.'","'.$date.'","","'.addslashes($messline).'","1/1","'.$session_key.'","'.$key.'"'.$check2.')');
  if ($web['regadd'] > 0) {
    @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`) VALUES ("'.$_POST['username'].'","0","用户注册","'.$web['regadd'].'","'.$date.'")', $db);
  }
  if ($bar_face_contents) {
    @mysql_query('REPLACE INTO `'.$sql['pref'].''.$sql['data']['承载上传数据的表名'].'` (`title`,`text`,`type`,`username`,`date`) VALUES ("face-'.$_POST['username'].'.'.$web['img_up_format'].'","'.addslashes($bar_face_contents).'","image/'.($web['img_up_format']=='jpg'?'jpeg':$web['img_up_format']).'","'.$_POST['username'].'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR))', $db);
  }

  $secces = @mysql_affected_rows();
  if ($secces > 0) {
    if ($web['stop_reg'] !== 2) {
      $you = array(
        'name'  => $_POST['username'],
        'key'   => $session_key,
        'point' => $web['loginadd'],
        'power' => '',
      );

      setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], time() + floatval($web['time_pos']) * 3600, '/', '.'.$web['root']);
      setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], time() + floatval($web['time_pos']) * 3600, '/');
    }


    $yougourl = '<table width="100%" border="0" cellspacing="10" cellpadding="0" class="wherego"><tr>';
    $yougourl .= '<td class="whereyou">您可以选择去向：</td><td align="left"><ul><li><a href="./">首页</a></li><li><a href="member.php">用户中心</a></li><li><a href="write.php">发布文章</a></li><li><a href="'.$loc.'">'.$loc.'</a></li></ul></td>';
    $yougourl .= '</tr>
</table>';

    @mysql_close();
    alert('注册成功！欢迎您 '.$you['name'].'。'.$check3.$yougourl.'', $loc);

  } else {
    err('注册不成功！['.mysql_errno().':'.mysql_error().']');
  }



//解除绑定
} elseif ($_GET['act'] == 'del_tie') {

  //身份验证
  define('POWER', confirm_power());

  if (!POWER >= 1) {
    err('系统检测你未登陆，没有权限。');
  }

  if ($_GET['bar'] != 'qq' && $_GET['bar'] != 'weibo' && $_GET['bar'] != 'baidu' && $_GET['bar'] != '162100') {
    err('参数不对！');
  }

  if (!isset($sql['db_err'])) {
    db_conn();
  }
  if ($sql['db_err'] != '') {
    err($sql['db_err']);
  }

  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET login_key_'.$_GET['bar'].'="" WHERE username="'.$session[0].'" LIMIT 1', $db);

  @mysql_close();
  alert('已解除<img src="inc/images/'.$_GET['bar'].'.png" width="16" height="16" />绑定！', $loc);



} else {
  err('参数出错！');
}





//基础管理员任何故障下登陆
function base_manager_login($boin = 0) {
  global $web, $sql, $date, $loc, $cookie_time, $js_say2, $db;
  $_POST['username'] = str_replace('.', '&#46;', $_POST['username']);
  if ($_POST['username'] == $web['manager']){
    if (md162100($_POST['password']) != $web['password']) {
      err('登陆失败！原因分析：管理员密码不符');
    }
    $you = array(
      'name'  => $_POST['username'],
      'key'   => $date.'|'.s_rand(16),
      'point' => 1000,
      'power' => 'm',
    );

    if (!file_exists('__temp__/temp')) {
	  if (!@mkdir('__temp__/temp', 0777)) {
        err('上载目录不存在！又无创建权限！登录被禁止。请手动建立__temp__/temp目录再重登录。');
      }
    }
    write_file('__temp__/temp/'.urlencode($you['name']).'.php', '<?php die(); ?>'.$you['key'].''); //登录密钥记录

    setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], $cookie_time, '/', '.'.$web['root']);
    setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], $cookie_time, '/');

    if ($boin == 1) {
      @ require ('inc/set/set_mail.php');
      @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` (`username`,`password`,`email`,`power`,`thisdate`,`regdate`,`company_description`,`mess`,`session_key`) values ("'.$web['manager'].'","'.$web['password'].'","'.($web['sender']?$web['sender']:'管理员邮箱未填写').'","m","'.$date.'","'.$date.'","","","'.$you['key'].'")', $db);
      //echo mysql_errno().':'.mysql_error();
    }



  if ($_POST['m'] == 1) {
    err($js_say2.'
<script language="javascript" type="text/javascript">
  if(sIs==true){
try{pS.innerHTML=\'<b>'.$you['name'].'</b> '.user_class(5, $row['point']).' | <a href="member.php">用户中心</a> | <a href="member.php?post=login&act=logout&m=1" onclick="return logoutM(this);">退出</a>\';}catch(e){}
  }
  </script>');
  }

    alert('以基础管理员身份登陆成功！欢迎您 '.$you['name'].'', $loc);
  } else {
    err('登陆失败！原因分析：管理员名称不符');
  }
}

function s_rand($l) {
  $rand = '';
  $c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz_0123456789';
  $n = strlen($c) - 1;
  for ($i = 0; $i < $l; $i++) {
    $rand .= $c[mt_rand(0, $n)];
  }
  return $rand;
}

function tirm_all($str) {
  return filter1(strtolower($str), 0);
}

function md162100($str) {
  return substr(sha1(md5($str)), 4, 32);
}


?>



