利用php调用discuz登录框方法有很多种,最常用的就是直接使用iframe方式调用了,还有就是直接在php页面中调用了,下面小编来给大家总结一些常用的方法。 
方法一,直接使用iframe调用一个加了discuz登录功能的页面 |  代码如下 |  
 |   <iframe src="/login.html" style="width:100%; height:32px" scrolling="no" frameborder="0" ></iframe>  |  
  
login.html代码
 |  代码如下 |  
 |  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title> c-gd.com-登录</title> 
<style type="text/css"> 
<!-- 
* { 
 margin:0; 
 padding:0; 
} 
body { 
 font: normal 12px Arial, Helvetica, Sans-Serif, "宋体"; 
 line-height: 160%; 
 text-align:left; 
 color: #3a3a3a; 
 margin:0; 
 padding:0; 
} 
img { 
 border:0; 
} 
ul, li { 
 padding:0; 
 margin:0; 
 list-style:none; 
} 
a { 
 text-decoration: none; 
 color:#3a3a3a; 
} 
a:hover { 
 color: #C00; 
} 
.banner { 
 margin-bottom:1px; 
 height:59px; 
} 
.denglu { 
 height:31px; 
 border-bottom:1px solid #FFF; 
 background:#e7e3e4; 
 color:#7b797a; 
} 
.denglu a { 
 color:#7b797a; 
 text-decoration:none; 
} 
.denglu a:hover { 
 color:#C00; 
 text-decoration:underline; 
} 
.denglu .box01 { 
 margin-left:30px; 
 float:left; 
 width:224px; 
 line-height:30px; 
 height:31px; 
} 
.denglu .box02 { 
 width:433px; 
 float:left; 
 color:#000; 
 text-align:right; 
} 
.denglu .box02 input { 
 border:1px #c5c3c3 solid; 
 height:20px; 
 width:88px; 
 background:#FFF; 
 line-height:20px; 
 margin-top:5px; 
} 
.denglu .box02 .button { 
 background:url(/static/image/common/img01.gif) no-repeat; 
 width:50px; 
 height:21px; 
 border:0; 
 color:#4b4b4b; 
 margin:0 5px; 
 font-size:12px; 
 line-height:20px; 
} 
.denglu .box03 { 
 float:right; 
 line-height:30px; 
 height:31px; 
 margin-right:15px; 
} 
.denglu .box03 .font1 { 
 margin-left:20px;  
} 
.denglu .box03 .font2 { 
 margin-left:10px; 
 background:url(/static/image/common/icon03.jpg) left center no-repeat; 
 padding-left:8px; 
 margin-left:40px; 
} 
--> 
</style> 
<script type="text/javascript"> 
function checkform(){ 
 if(document.getElementById('username').value==''){ 
  alert('请输入用户名'); 
  return false; 
 } 
 if(document.getElementById('password').value==''){ 
  alert('请输入密码'); 
  return false; 
 }  
 return true; 
} 
  
function showDate() 
{ 
var d = new Date();   
document.write("<div class='date_div'>"+d.getYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日"); 
switch(d.getDay()) 
{ 
 case 0: 
  document.write("  星期日"); 
  break; 
 case 1: 
  document.write("  星期一"); 
  break; 
 case 2: 
  document.write("  星期二"); 
  break; 
 case 3: 
  document.write("  星期三"); 
  break; 
 case 4: 
  document.write("  星期四"); 
  break; 
 case 5: 
  document.write("  星期五"); 
  break; 
 case 6: 
  document.write("  星期六"); 
  break; 
} 
 document.write("</div>"); 
} 
</script> </head> 
<body> 
<div id="header"> 
  <!--登录--> 
  <div class="denglu"> 
    <div class="box01"> 
 <script language="JavaScript" type="text/JavaScript"> 
showDate(); 
</script>    </div> 
         <form method="post" action="/bbs/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes"> 
     <div class="box02"> 
     用户名:<input type="text" name="username" id="username" /> 
         密码:<input type="password" name="password" id="password"  /> 
             <input type="hidden" name="quickforward" value="yes" /> 
               <input type="hidden" name="handlekey" value="ls" /> 
               <input type="hidden" name="iflogin" value="plus.php?mod=iframelogin" /> 
      <span> 
      <input name="input" type="submit"  class="button" value="登录" style="cursor:pointer" /> 
      </span> 
      <span> 
      <input name="input" type="button"  class="button" value="注册" style="cursor:pointer"/> 
      </span> 
      </div> 
      </form> 
     
    <div class="box03"> 
    <span class="font2"><a href="javascript:;">设为首页</a></span> 
    <span class="font1"><a href="/" target="_parent">中文</a> | <a href="#"  target="_parent">English</a></span> 
     
    </div> 
  
     
  </div> 
</div> 
</body> 
</html>  |  
 方法二,利用php方式调用了 在自定义的PHP页面里加入discuz登陆框。PHP如何调用discuz登陆框。 |  代码如下 |  
 |  <?php 
 error_reporting(0); 
 require 'source/class/class_core.php'; 
 $discuz = & discuz_core::instance(); 
 $discuz->init(); 
if (empty($_G['uid'])) { 
?> 
  
<form target="_blank" action="member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes" method="post" name="form2"> 
 <span>用户名:<input name="username" type="text" id="textfield2" size="13" tabindex="1" value="请输入用户名"> 
 密码:<input name="password" type="password" id="password" size="12"> 
 <input type="submit" name="button2" id="button2" value="登录"> 
 <a href="member.php?mod=register" target="_blank">注册</a>  
 <a href="member.php?mod=logging&action=login&viewlostpw" target="_blank">找回密码</a> 
 <input type="hidden" name="referer" value="/" /></span> 
</form> 
  
<?php } else { ?> 
  
<div> 
尊敬的<a href="home.php?mod=space&uid=<?php echo $_G['uid']; ?>&do=profile" target="_blank"><? echo $_G['username']; ?></a>,欢迎您光临!  | <a href="home.php?mod=space&do=thread&view=me" target="_blank">我的帖子</a> |  <a href="home.php" target="_blank">个人中心</a> |  <a href="member.php?mod=logging&action=logout&formhash=<? echo FORMHASH;?>" target="_blank">退出登陆</a> 
</div> 
  
<?php }?> |  
  
方法三:discuz登陆框是ajax调用的,一开始在firebug下看到了调用了接口:
 |  代码如下 |  
 |  | /member.php  ?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login |  
   
这返回的是一个xml的内容,其中就一个结点root,里面会根据本地的cookies判断是否登录了论坛,如果没有登陆 里面的内容就是一段form登陆表单。如果登陆了里面就是一段登陆后的信息。然后将ajax请求中的css保存到本 地。能够实现登陆框调用。登陆框中有一个hidden的input name=‘reffer’ 这里面的value值是来路链接.不过要是 论坛程序里的。比如将这个连接换成h/home.php?mod=spacecp&ac=blog这样登陆完后会 自动跳转到发博客的页面。可以实现一键发帖功能。 代码如下: |  代码如下 |  
 |  <?php   
$login = file_get_contents("/member.php?   
mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login");  
require_once('SofeeXmlParser.php');//xml解析类 博客里搜索xml有相关介绍   
$xml = new SofeeXmlParser();   
$xml->parseString($login);   
$tree = $xml->getTree();   
$login = str_replace("member.php","h/member.php",$tree["root"]["value"]);   
$login = str_replace("h/./","h/home.php?   
mod=spacecp&ac=blog",$login);//跳转到发帖页面   
$login = preg_replace('/<h3 class="flb">(.*)</h3>/i','',$login);   
var_dump($login);   
exit();   
$login = iconv('utf-8','gbk',$login);   
     
echo $login;   
?>  |  
  
 |