| 
 
     
 
  | 
激活文件:activate.php- <?php
 
  
- require_once 'config_db.php';
 
  
 
- //我这里使用的是GET方式
 
  
- $uid = empty($_GET['uid'])?0:intval($_GET['uid']);
 
  
- $username = trim($_GET['username']);
 
  
- $password = trim($_GET['password']);
 
  
- $email = trim($_GET['email']);
 
  
- $regip = trim($_SERVER['REMOTE_ADDR']);
 
  
- $regdate = time();
 
  
- //echo $uid." ".$username."<br />";
 
  
- $existuid = 0;
 
  
- $existuname = "";
 
  
- $existuid2 = 0;
 
  
- $existuname2 = "";
 
  
 
- //先从UC会员表dz_uc_members中查找
 
  
- $sql01 = "select uid,username from dz_uc_members where uid=$uid and username='$username'";
 
  
- foreach ($dbh->query($sql01) as $row01) {
 
  
-        $existuid = $row01['uid'];
 
  
-        $existuname = $row01['username'];
 
  
- }
 
  
 
- //echo "1. ".$existuid." ".$existuname."<br />";
 
  
- //如果uc_members中存在,下一步
 
  
- if ($existuid!="" && $existuid>0) {
 
  
 
- //再从discuz会员表dz_members中查找
 
  
- $sql02 = "select uid,username from dz_members where uid=$uid and username='$username'";
 
  
- foreach ($dbh->query($sql02) as $row02) {
 
  
-        $existuid2 = $row02['uid'];
 
  
-        $existuname2 = $row02['username'];
 
  
- }
 
  
- //echo "2. ".$existuid2." ".$existuname2."<br />";
 
  
- //如果dz_members中不存在,则激活
 
  
- if ($existuid2=="" || $existuid2<=0) {
 
  
-        $sqlac="insert into dz_members (uid,username,password,email,adminid,groupid,regip,regdate,lastip,lastvisit,timeoffset) values ('$uid','$username','$password','$email','0','10','$regip','$regdate','$regip','$regdate','9999')";
 
  
-        try {
 
  
-               $dbh->beginTransaction();
 
  
-               $dbh->exec($sqlac);
 
  
-               $dbh->commit();
 
  
-        } catch (Exception $e) {
 
  
-               $dbh->rollBack();
 
  
-               echo "Failed: " . $e->getMessage();
 
  
-        }
 
  
-        $sqlac="insert into dz_memberfields (uid, nickname, site, alipay, icq, qq, yahoo, msn, taobao, location, customstatus, medals, avatar, avatarwidth, avatarheight, bio, sightml, ignorepm, groupterms, authstr, spacename, buyercredit, sellercredit) values ('$uid', '', '', '', '', '', '', '', '', '', '', '', '', '0', '0', '', '', '', '', '', '', '0', '0');";
 
  
-        try {
 
  
-               $dbh->beginTransaction();
 
  
-               $dbh->exec($sqlac);
 
  
-               $dbh->commit();
 
  
-        } catch (Exception $e) {
 
  
-               $dbh->rollBack();
 
  
-               echo "Failed: " . $e->getMessage();
 
  
-        }
 
  
-        //echo "激活成功!";
 
  
- }
 
  
 
- }
 
  
- $dbh = null;
 
  
- ?>
 
  复制代码 数据库连接:config_db.php- <?php
 
  
- $dbhost = 'localhost';
 
  
- $dbuser = 'yutiedun';
 
  
- $dbpw = '111111';
 
  
- $dbname = 'discuz';    
 
  
- $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpw);
 
  
- $dbh->query("set names 'gbk'");
 
  
- ?>
 
  复制代码 |   
 
 
 
 |