Php implementation code for obtaining information such as the login user name, user group, and user ID of the Discuz Forum _ php instance

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.