Discuz! X2.5判断会员登录状态及外部调用注册登录框
有关discuz论坛会员信息,收集的一些资料:
用dedecms+discuz做了个门户加论坛形式的网站,但是dedecms顶部目前只能qq登录或注册。即使登录后返回也首页也还是这样。
想做的效果是如果登录之后会调用discuz的登录状态.
我自己弄出来了,贴代码分享。
第一部
在discuz下写个php文件
<?php require './source/class/class_core.php'; $discuz = & discuz_core::instance(); $discuz->init_cron = false; $discuz->init_session = false; $discuz->init(); //echo $_G['uid']; echo $_G['username']; ?>
放到discuz根目录 随便取个.PHP文件名。用来获取当前登录用户信息
第二步
利用ajax获取该页面的值
我就不多写了 用我刚写的例子
<div class="r" id="denglu" style="display:none;"> 尊敬的 <a href="/bbs"></a> 您好! </div> <div class="r" id="weidenglu" style="display:none;">请<a href="/bbs/connect.php?mod=login&op=init&referer=forum.php&statfrom=login_simple" id="index_login">QQ登录</a>或<a href="/bbs/member.php?mod=register" target="_blank" id="index-reg">注册</a></div> <script> $(document).ready(function(){ $('#denglu a').load("/bbs/userinfo.php",function(data){ var cq=data; if(cq){ $('#weidenglu').remove(); $('#denglu').show(); } else{ $('#denglu').remove(); $('#weidenglu').show(); } }); }); </script>
参考资料:
分享一个外部调用会员登陆窗口的解决办法【原创】for discuz 7.2
如何在站外调用discuz登陆框和登录状态页面? discuz X2.5
(补充一下,如果一个网站使用了Jquery和Prototype二个JS库的话,要注意写jQuery.noConflict();。不然load函数不会生效,因为二个JS库冲突了)
http://www.w3school.com.cn/jquery/core_noconflict.asp 具体的用法,自己去w3school看