Synchronous login and exit of discuznt forum and main site

Source: Internet
Author: User

Forum Domain Name: forum.web.net (virtual)
The website domain name is www.web.net (Virtual too)
Log on to the background of the Forum with an administrator account and set "authentication cookie domain:" To .web.net.
After the Forum is configured, copy the discuz. forum. DLL, discuz. entity. DLL, discuz. data. DLL, discuz. data. sqlserver. DLL and discuz. common. DLL to the bin of the website. Similarly, DNT. config is stored in the root directory of the website.
Post Code You can see more clearly. Copy code The Code is as follows: using system;
Using system. collections;
Using system. configuration;
Using system. Data;
Using system. Web;
Using discuz. Forum;
Using discuz. Common;
Using discuz. entity;

Namespace website
{
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
// The following judgment function is: Check whether the cookie contains the userid of the Forum. If so, it indicates that a user has logged on.
If (request. Cookies ["DNT"]! = NULL & request. Cookies ["DNT"]. Values ["userid"]! = NULL)
{
// Obtain the userid from the cookie
Int uid = convert. toint32 (request. Cookies ["DNT"]. Values ["userid"]. tostring ());
// Obtain all the information of this user
Userinfo A = discuz. Forum. Users. getuserinfo (UID );
// Print it out to see if it is correct.
Response. Write (A. username );
// This code exits! Clear cookie !!!
Forumutils. clearusercookie ();
}
Else // No user? How can I log on!
{
// Set two variables first
String uname = "Rohan ";
String upass = "mypassword ";
// Verify that userid is returned if the user logs on. Otherwise,-1 is returned.
Int uid = users. checkpassword (uname, upass, true );
If (UID! =-1)
{
// The following are the content in the official integration instructions.
Loginlogs. deleteloginlog (dntrequest. getip ());
// Refresh the total user points based on the Integral Formula
Usercredits. updateusercredits (UID );
// Write the cookie after User Login
// Note that there is something special here. The original Article is
// Forumutils. writeusercookie (UID, utils. strtoint (dntrequest. getstring ("expires"),-1), config. passwordkey, dntrequest. getint ("templateid", 0), dntrequest. getint ("loginmode",-1 ));
// Here, I extract config. passwordkey from the node of the General. config file in the config folder of the Forum. In this way, you do not need to copy Forum-related files to your website.
Forumutils. writeusercookie (UID, utils. strtoint (dntrequest. getstring ("expires"),-1), "r254842j4z", dntrequest. getint ("templateid", 0), dntrequest. getint ("loginmode",-1 ));

// Update the last access time of the user
Users. updateuserlastvisit (UID, dntrequest. getip ());

}
}

}

}
}

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.