PHP to get Discuz forum login user name user group user ID and other information implementation code

  • 2020-03-31 21:23:02
  • OfStack

Here's a simple way to log in directly using discuz's include/common.inc. PHP.
 
include_once("../discuz/include/common.inc.php"); 
$CTDF_USERINFO = array(); 
$CTDF_USERINFO["sid"] = $sid; 
$CTDF_USERINFO["uid"] = $discuz_uid; 
$CTDF_USERINFO["user"] = $discuz_user; 
if ($discuz_uid == 0) 
{ 
$CTDF_USERINFO["user"] = "guest_" . $sid; 
} 
$CTDF_USERINFO["groupid"] = $groupid; 
 
$reserved_arr = array("GLOBALS", "_POST", "_GET", "_COOKIE", "_FILES", "_SERVER", "_ENV", "_REQUEST", "CTDF_USERINFO", "reserved_arr"); 
foreach ($GLOBALS as $key => $value) 
{ 
if (!in_array($key, $reserved_arr)) 
{ 
unset($GLOBALS[$key]); 
} 
} 
unset($reserved_arr, $value); 

The above code is placed at the beginning of any program in order not to affect the use of custom variables. This reads the login information into the $CTDF_USERINFO array.

Or this is relatively simple oh, look for a long time, this is cool

Related articles: