In the previous article, I used cookies and discuz databases to retrieve user names, user groups, user IDs, and other information, but that information is not necessarily accurate, because the auth value in the COOKIE is used for dynamic login during discuz login, and the cookie information is lagging, the obtained information is not completely accurate. Here is a simple method to log on directly using discuz's include/common. inc. php.
The code is as follows:
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;
/**
* Clear discuz variables
*/
$ 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 );
Place the above code at the beginning of any program, so as not to affect the use of custom variables. In this way, the logon information is read to the $ CTDF_USERINFO array.
It's still relatively simple. I 've been searching for a long time and it's so nice this time.