dedecms 与 discuz 用户集成登录解决思路

本人接了个项目,织梦的dedecms与DISCUZ集成在一起。

用户打通以后,我把用户激活功能去掉了。

接着,发现在织梦中登录后,在DISCUZ中还要再登录一次,真是恼火。

解决办法有三种:

1、第一种办法:找到两个系统的cookie,修改相关代码,使得两者保持同步。(难度系数,高,我还没搞清楚)

2、第二种办法:织梦登录以后,调用member/index_do.php。

将代码

ShowMsg("成功登录,5秒钟后转向系统主页…","../index.php",0,2000);

修改成:

setcookie("lhuserid", $userid);setcookie("lhpwd", $pwd);ShowMsg("成功登录,5秒钟后转向系统主页…","autopost.php",0,2000);

代码的意思是在跳转到../index.php之前,取得用户用户和密码,存入cookie。

然后跳转到一个另外的php文件autopost.php,autopost.php代码如下:

<?phpecho "<html>";echo "<head>";echo "<title>hello post test</title>";echo "<script>";echo "function winurl(){";echo "document.getElementById(‘loginsubmit’).click();";echo "}";echo "setTimeout(‘winurl()’,1);";echo "</script>";echo "<SCRIPT language=’JavaScript’> ";echo "javascript:window.history.forward(1); ";echo "</script>";echo "</head>";echo "<body>";echo "登录成功!";echo " <div >echo " <form method=’post’ autocomplete=’off’ name=’login’ id=’loginform_L9xrs’ class=’cl’ action=’http://bbs.xxxx.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=L9xrs’>";echo "<div class=’c cl’>";echo " <input type=’text’ name=’username’ id=’username_L9xrs’ value=’";//echo $_COOKIE[‘lhuserid’];//echo $lhuserid;

//取得用户cookie值if(isset($_COOKIE["lhuserid"])){echo $_COOKIE["lhuserid"];} //echo $_POST["username"];//echo "szliszt";echo "’ autocomplete=’off’ size=’36’ class=’txt’ tabindex=’1′ value=” /><input type=’password’ id=’password3_L9xrs’ name=’password’ value=’";//echo $_COOKIE["pwd"] ;//echo $_POST["password"];if(isset($_COOKIE["lhpwd"])){echo $_COOKIE["lhpwd"];} //echo "123456";echo "’ size=’36’ class=’txt’ tabindex=’1′ /><button class=’pn pnc’ type=’submit’ name=’loginsubmit’ value=’true’"; echo " tabindex=’1′><span>µÇ¼</span></button>";echo " </div></form>";echo " </div>";echo "</body>";echo "</html> ";?>

autopost.php调用后会自动执行,把首页传过来的帐号密码立即提交,实现在disuz中登录成功。

此方法的缺陷是,在登录成功后,discuz总是试图返回,老刷新。怎么解决还没想到好办法。

注意,如果文件不在同一个目录下,会取不到cookie值的。

(此方法难度系数,中)

3、第三种方法:

修改织梦首页的模板文件index.html,

在<div class="loglink"> 之前加上隐藏的登录信息(其实写在别的位置也可以),代码如下

<div > <form method="post" autocomplete="off" name="login" id="loginform_L9xrs" class="cl" onsubmit="pwdclear = 1;return false;" action="http://bbs.xxxx.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=L9xrs"><div class="c cl"> <input type="text" name="username" id="username_L9xrs" autocomplete="off" size="36" class="txt" tabindex="1" value="" /><input type="password" id="password3_L9xrs" name="password" onfocus="clearpwd()" onkeypress="detectCapsLock(event, this)" size="36" class="txt" tabindex="1" /><button class="pn pnc" type="submit" name="loginsubmit" value="true" tabindex="1"><span>怬</span></button> </div></form> </div>

然后修改前面的提交按钮,实现自动同步填充帐号密码,自动提交的效果

<input type="text" name="userid" size="20" class="ipt-txt" />

修改成

<input type="text" name="userid" size="20" onblur="document.getElementById(‘username_L9xrs’).value=document.getElementById(‘userid’).value" onchange="document.getElementById(‘username_L9xrs’).value=document.getElementById(‘userid’).value" class="ipt-txt" />

<input type="password" name="pwd" size="20" class="ipt-txt" />

修改成

<input type="password" name="pwd" onchange="document.getElementById(‘password3_L9xrs’).value=document.getElementById(‘pwd’).value" size="20" class="ipt-txt" />

<button type="submit" class="btn-1" >

修改成

<button type="submit" class="btn-1" onclick="document.getElementById(‘loginsubmit’).click();" >

当在首页输入帐号密码的时候,隐藏的用户名和密码框会自动输入相同数据,提交的时候,也会自动提交一份到discuz中。

(此方法难度系数,低)

网上资料实在太少了,痛苦摸索了好几天,终于解决了,与大家共享。

伟人所达到并保持着的高处,并不是一飞就到的,

dedecms 与 discuz 用户集成登录解决思路

相关文章:

你感兴趣的文章:

标签云: