PHPBB3 can be used with websites to log on to the Forum at the same time.

Source: Internet
Author: User
PHPBB3 can be used with websites to log on to the Forum at the same time, and PHPBB3 can be used with websites to log on to the Forum at the same time. so I studied this. the main idea is to simulate COOKIES .. first, insert the user ID and SessionID into the Cookies, and then insert the SessionID into the sessions table in the database. "> <LIN

This is required for work reasons, so I have studied it.

The main idea is to simulate COOKIES .. first, insert the user ID and SessionID into the Cookies, and then insert the SessionID and user ID into the sessions table of the database. if you open the forum, the system will verify whether the cookie information is the same as the information in the database. if the information is the same, automatic login can be implemented .. the main logon code is as follows:

// Obtain a 32-bit random SESSIONID
// Initialize each value
$ Session_testId = create_sess_id (32 );
$ SessionIp = '192. 168.0.100 ';
$ Cookie_path = '/';
$ CookieName = 'phpbb3 _ 1w36a ';
$ UserBrowserInfo = $ _ SERVER ["HTTP_USER_AGENT"];
$ UserIpAdd = $ _ SERVER ["REMOTE_ADDR"];

// Obtain the user name and password of the form
$ Pai_username = $ _ POST ["username"];
$ Pai_password = $ _ POST ["password"];
// Verify with the CMS system table first. if you pass the. query the ID in the BBS user table of the corresponding user name

$ Link = mysql_connect ("localhost", "root ","");
Mysql_select_db ("cms ");
$ SelectUid = "select user_id from bbs_users where username = '$ username '";
$ UidResult = mysql_query ($ selectUid );
$ UserId = null;
While ($ row1 = mysql_fetch_array ($ uidResult, MYSQL_NUM ))
{
$ UserId = $ row1 [0];
}
// Echo $ userId;
Mysql_close ($ link );

// Insert user ID information into Cookies
Setcookie ($ cookieName. '_ U', $ userId, time () + 100000000, $ cookie_path, $ SessionIp, false );
// Insert SessionID information into Cookies
Setcookie ($ cookieName. '_ sid', $ Session_testId, time () + 100000000, $ cookie_path, $ SessionIp, false );

// Insert Session information to the phpb_sessions table
$ Link = mysql_connect ("localhost", "root ","");
Mysql_select_db ("cms ");
$ Sqlcommand = "insert into bbs_sessions (session_id, session_user_id, session_last_visit, session_start, session_time, session_ip, session_browser, session_page )";
$ Sqlcommand. = "values ('$ Session_testId', $ userId ,'". time (). "','". time (). "','". time (). "',' $ useripadd', '$ userBrowserInfo', 'index. php ')";

// Echo $ sqlcommand;

Mysql_query ($ sqlcommand );
Mysql_close ($ link );


// Generate a 32-bit random number
Function create_sess_id ($ len = 32)
{
// Obtain the microseconds of the current time
List ($ u, $ s) = eXPlode ('', microtime ());
$ Time = (float) $ u + (float) $ s;
// Generate a random number
$ Rand_num = rand (100000,999 999 );
$ Rand_num = rand ($ rand_num, $ time );
Mt_srand ($ rand_num );
$ Rand_num = mt_rand ();
// Generate SessionID
$ Sess_id = md5 (md5 ($ time). md5 ($ rand_num ));
// Intercept the specified SessionID.
$ Sess_id = substr ($ sess_id, 0, $ len );
Return $ sess_id;
}
Header ("location: http: // 192.168.0.100/bbs/index. php ");
// Print_r ($ _ COOKIE );
?>

In this way, automatic login is enabled.

Of course, this is not enough. we also need to block users in PHPBB from modifying account information and registering new users. for example, if you want to modify registration, you can modify

Phpbb3rc2 \ styles \ prosilver \ templatethe .ucp_register.html template under this directory. delete the content. add this

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.