>백엔드 개발 >PHP 튜토리얼 >discuz论坛 用户登录 后台程序代码_PHP

discuz论坛 用户登录 后台程序代码_PHP

PHP中文网
PHP中文网원래의
2016-06-01 12:24:141093검색

还好,用户登录这里通过一个小小的方法可以实现和论坛同步了.可以不用passport接口.
这是我整理的数据,仅供参考.
登录传两值过来就行(username和password);
代码如下:

<?php 
session_start(); 
define(&#39;NOROBOT&#39;, TRUE); 
define(&#39;CURSCRIPT&#39;, &#39;logging&#39;); 
require_once &#39;./include/common.inc.php&#39;; 
require_once DISCUZ_ROOT.&#39;./include/misc.func.php&#39;; 
if($action == &#39;login&#39;) { 
$field = $loginfield == &#39;uid&#39; ? &#39;uid&#39; : &#39;username&#39;; 
//get secure code checking status (pos. -2) 
$seccodecheck = substr(sprintf(&#39;%05b&#39;, $seccodestatus), -2, 1); 
if($seccodecheck && $seccodedata[&#39;loginfailedcount&#39;]) { 
$seccodecheck = $db->result($db->query("SELECT count(*) FROM {$tablepre}failedlogins WHERE ip=&#39;$onlineip&#39; AND count>=&#39;$seccodedata[loginfailedcount]&#39; AND $timestamp-lastupdate<=900"), 0); 
} 
$discuz_uid = 0; 
$discuz_user = $discuz_pw = $discuz_secques = $md5_password = &#39;&#39;; 
$member = array(); 
$loginperm = logincheck(); 
if(!$loginperm) { 
showmessage(&#39;login_strike&#39;); 
} 
$secques = quescrypt($questionid, $answer); 
if(isset($loginauth)) { 
$field = &#39;username&#39;; 
$password = &#39;VERIFIED&#39;; 
list($username, $md5_password) = daddslashes(explode("\t", authcode($loginauth, &#39;DECODE&#39;)), 1); 
} else { 
$md5_password = md5($password); 
$password = preg_replace("/^(.{".round(strlen($password) / 4)."})(.+?)(.{".round(strlen($password) / 6)."})$/s", "\\1***\\3", $password); 
} 
$query = $db->query("SELECT m.uid AS discuz_uid, m.username AS discuz_user, m.password AS discuz_pw, m.secques AS discuz_secques, 
m.adminid, m.groupid, m.styleid AS styleidmem, m.lastvisit, m.lastpost, u.allowinvisible 
FROM {$tablepre}members m LEFT JOIN {$tablepre}usergroups u USING (groupid) 
WHERE m.$field=&#39;$username&#39;"); 
$member = $db->fetch_array($query); 
//判断登录是否正确 
if($member[&#39;password&#39;]!=$md5_password){ 
echo "您输入的用户名或密码错误!"; 
exit(); 
} 
//通过就执行下边的程序 
extract($member); 
$discuz_userss = $discuz_user; 
$discuz_user = addslashes($discuz_user); 
if(($allowinvisible && $loginmode == &#39;invisible&#39;) || $loginmode == &#39;normal&#39;) { 
$db->query("UPDATE {$tablepre}members SET invisible=&#39;".($loginmode == &#39;invisible&#39; ? 1 : 0)."&#39; WHERE uid=&#39;$member[discuz_uid]&#39;", &#39;UNBUFFERED&#39;); 
} 
$styleid = intval(empty($_POST[&#39;styleid&#39;]) ? ($styleidmem ? $styleidmem : 
$_DCACHE[&#39;settings&#39;][&#39;styleid&#39;]) : $_POST[&#39;styleid&#39;]); 
$cookietime = intval(isset($_POST[&#39;cookietime&#39;]) ? $_POST[&#39;cookietime&#39;] : 
($_DCOOKIE[&#39;cookietime&#39;] ? $_DCOOKIE[&#39;cookietime&#39;] : 0)); 
dsetcookie(&#39;cookietime&#39;, $cookietime, 31536000); 
dsetcookie(&#39;auth&#39;, authcode("$discuz_pw\t$discuz_secques\t$discuz_uid", &#39;ENCODE&#39;), $cookietime); 
$sessionexists = 0; 
updatesession();//更新论坛USERPASS数据 
echo "{&#39;action&#39;:&#39;ture&#39;}";//这里是您要输出的数据 
print_r($_DSESSION); 
echo $discuz_userss; 
} 
?>


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.