返回列表 发帖

[Discuz!相关] Discuz自动激活UCenter用户

激活文件:activate.php
  1. <?php

  2. require_once 'config_db.php';


  3. //我这里使用的是GET方式

  4. $uid = empty($_GET['uid'])?0:intval($_GET['uid']);

  5. $username = trim($_GET['username']);

  6. $password = trim($_GET['password']);

  7. $email = trim($_GET['email']);

  8. $regip = trim($_SERVER['REMOTE_ADDR']);

  9. $regdate = time();

  10. //echo $uid." ".$username."<br />";

  11. $existuid = 0;

  12. $existuname = "";

  13. $existuid2 = 0;

  14. $existuname2 = "";


  15. //先从UC会员表dz_uc_members中查找

  16. $sql01 = "select uid,username from dz_uc_members where uid=$uid and username='$username'";

  17. foreach ($dbh->query($sql01) as $row01) {

  18.        $existuid = $row01['uid'];

  19.        $existuname = $row01['username'];

  20. }


  21. //echo "1. ".$existuid." ".$existuname."<br />";

  22. //如果uc_members中存在,下一步

  23. if ($existuid!="" && $existuid>0) {


  24. //再从discuz会员表dz_members中查找

  25. $sql02 = "select uid,username from dz_members where uid=$uid and username='$username'";

  26. foreach ($dbh->query($sql02) as $row02) {

  27.        $existuid2 = $row02['uid'];

  28.        $existuname2 = $row02['username'];

  29. }

  30. //echo "2. ".$existuid2." ".$existuname2."<br />";

  31. //如果dz_members中不存在,则激活

  32. if ($existuid2=="" || $existuid2<=0) {

  33.        $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')";

  34.        try {

  35.               $dbh->beginTransaction();

  36.               $dbh->exec($sqlac);

  37.               $dbh->commit();

  38.        } catch (Exception $e) {

  39.               $dbh->rollBack();

  40.               echo "Failed: " . $e->getMessage();

  41.        }

  42.        $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');";

  43.        try {

  44.               $dbh->beginTransaction();

  45.               $dbh->exec($sqlac);

  46.               $dbh->commit();

  47.        } catch (Exception $e) {

  48.               $dbh->rollBack();

  49.               echo "Failed: " . $e->getMessage();

  50.        }

  51.        //echo "激活成功!";

  52. }


  53. }

  54. $dbh = null;

  55. ?>
复制代码
数据库连接:config_db.php
  1. <?php

  2. $dbhost = 'localhost';

  3. $dbuser = 'yutiedun';

  4. $dbpw = '111111';

  5. $dbname = 'discuz';   

  6. $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpw);

  7. $dbh->query("set names 'gbk'");

  8. ?>
复制代码
欢迎光临:逐梦论坛

谢谢!楼主提供!好样的











bjcars.net

TOP

好人一个啊











bjcars.net

TOP

呵呵你真厉害,佩服哦

TOP

返回列表

Powered by Discuz! 7.2   论坛QQ群:逐梦论坛群

© 2001-2021 Comsenz Inc. 鲁公网安备 37120302000001号