Home  >  Article  >  Backend Development  >  discuz forum user login background program code_PHP tutorial

discuz forum user login background program code_PHP tutorial

PHP中文网
PHP中文网Original
2016-07-21 15:48:421047browse

还好,用户登录这里通过一个小小的方法可以实现和论坛同步了.可以不用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; 
} 
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn