discuz 自定义注册和登录并且保持登录状态实例(原创)

摘要:discuz 自定义注册和登录并且保持登录状态实例...

作者:LoveCode标签:discuz,自定义,注册,登录,保持,登录状态,实例

discuz自定义注册页面并且保持登录状态:

<!--{eval}-->
if($_GET['act']=='register' && $_POST['FUCKYOU'] && $_POST['FUCKYOU']=='INTHERAIN' )
{
    include_once './config/config_ucenter.php';
    include_once './uc_client/client.php';
    $username = daddslashes($_POST['username']);
    $email = daddslashes($_POST['email']);
    $password = daddslashes($_POST['password']);

    $uid = uc_user_register($username, $password, $email);
    if($uid <= 0) {
        if($uid == -1) {
            $msg = '用户名不合法';
        } elseif($uid == -2) {
            $msg = '包含要允许注册的词语';
        } elseif($uid == -3) {
            $msg = '用户名已经存在';
        } elseif($uid == -4) {
            $msg = 'Email 格式有误';
        } elseif($uid == -5) {
            $msg = 'Email 不允许注册';
        } elseif($uid == -6) {
            $msg = '该 Email 已经被注册';
        } else {
            $msg = '未定义';
        }
    } else {
        $cookietime = 31536000;
        //echo $uid;
        $data = DB::fetch_all("SELECT * FROM ".DB::table('ucenter_members')." WHERE uid=".$uid." ");
        $uid = $data[0]['uid'];
        $username = $data[0]['username'];
        $password = $data[0]['password'];
        $email = $data[0]['email'];
        $ip = $_SERVER['REMOTE_ADDR'];
        $time = time();

        $member_data = array(
            'uid' => $uid,
            'username' => $username,
            'password' => $password,
            'email' => $email,
            'adminid' =>0,
            'groupid' =>10,
            'regdate' =>$time,
            'timeoffset' =>999
        );
        $status_data = array(
            'uid' =>$uid,
            'regip' => $ip,
            'lastip' => $ip,
            'lastvisit' => $time,
            'lastactivity' => $time
        );
        $arr_uid = array(
            'uid'=>$uid
        );
        DB::insert('common_member', $member_data);
        DB::insert('common_member_status', $status_data);
        DB::insert('common_member_profile', $arr_uid);
        DB::insert('common_member_field_forum', $arr_uid);
        DB::insert('common_member_field_home', $arr_uid);
        DB::insert('common_member_count', $arr_uid);
        dsetcookie('auth', authcode("$password\t$uid", "ENCODE"), $cookietime);

        $msg = '注册成功';

        //$rs = DB::query("INSERT INTO ".DB::table('common_member')." (`uid`, `username`, `password`, `email`, `regdate`) VALUES($uid, '".$username."', '".$password."', '".$email."', ".time().") ");
        //if($rs && $rs !=0)
         //   $msg = '注册成功';
           // uc_user_synlogin($uid);
        //}

        $EEE = <<<EEE
        <button data-toggle="modal" data-target="#register-status" name="register-status">注册状态</button>

        <div class="modal fade" id="register-status" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="msgShow">$msg</h4>
                    </div>
                    <div class="white-space"></div>
                    <a href="javascript:location.reload();" class="urlJump">如果没有跳转,点击此处</a>
                    <div class="white-space"></div>
                </div>
            </div>
        </div>

        <script>
            var e = jQuery('button[name="register-status"]');
            e.trigger('click');
            setInterval(function(){
                location.reload();
            }, 3000);
        </script>
EEE;

        echo $EEE;
    }

}
<!--{/eval}-->


discuz自定义登录页面并且保存登录状态:

<!--{eval}-->
if($_GET['act']=='login' && $_POST['FUCKYOU'] && $_POST['FUCKYOU']=='INTHERAIN' )
{
    include_once './config/config_ucenter.php';
    include_once './uc_client/client.php';
    $username_email = daddslashes($_POST['username_email']);
    $password = daddslashes($_POST['password']);
    $is_email = preg_match('/@(.+)\.(\w+)/i', $username_email);

    if($is_email)
    {
        list($uid, $username, $password, $email) = uc_user_login($username_email, $password, 2);
    }else
    {
        list($uid, $username, $password, $email) = uc_user_login($username_email, $password);
    }
    if($uid > 0) {
        $msg = '登录成功';
        $cookietime = 31536000;
        $data = DB::fetch_all("SELECT * FROM ".DB::table('ucenter_members')." WHERE uid=".$uid." ");
        $uid = $data[0]['uid'];
        $password = $data[0]['password'];
        dsetcookie('auth', authcode("$password\t$uid", "ENCODE"), $cookietime);
    } elseif($uid == -1) {
        $msg = '用户不存在,或者被删除';
    } elseif($uid == -2) {
        $msg = '密码错误';
    } else {
        $msg = '未定义';
    }

    $EEE = <<<EEE
    <button data-toggle="modal" data-target="#logging-status" name="logging-status">登录状态</button>
    <div class="modal fade" id="logging-status" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="msgShow">$msg</h4>
                </div>
                <div class="white-space"></div>
                <a href="javascript:location.reload();" class="urlJump">如果没有跳转,点击此处</a>
                <div class="white-space"></div>
            </div>
        </div>
    </div>

    <script>
        var e = jQuery('button[name="logging-status"]');
        e.trigger('click');
        setInterval(function(){
            //location.reload();
        }, 3000);
    </script>
EEE;
    echo $EEE;
}
<!--{/eval}-->
CopyRight © 2017 荒山本的官方网站 粤ICP备16049175号 All Right Service 网站地图(xml) 网站地图(html)