PHPBB3 integrates with the website to achieve simultaneous logon to the Forum _ PHP Tutorial

Source: Internet
Author: User
PHPBB3 can be used with websites to log on to the Forum at the same time. For work reasons. so I studied this. the main idea is to simulate COOKIES .. first, insert the user ID and SessionID into the Cookies, and then the sessions table in the database for work reasons. 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 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 = php (as the mainstream development language) bb3_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 (the best combination with PHP) _ connect ("localhost", "root ","");
MySQL (the best combination with PHP) _ select_db ("cms ");
$ SelectUid = "select user_id from bbs_users where username = $ pai_username ";
$ UidResult = MySQL (the best combination with PHP) _ query ($ selectUid );
$ UserId = null;
While ($ row1 = MySQL (the best combination with PHP) _ fetch_array ($ uidResult, MySQL (the best combination with PHP) _ NUM ))
{
$ UserId = $ row1 [0];
}
// Echo $ userId;
MySQL (the best combination with PHP) _ 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 into the B _sessions table of php (as the mainstream development language)
$ Link = MySQL (the best combination with PHP) _ connect ("localhost", "root ","");
MySQL (the best combination with PHP) _ 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 (as the mainstream development language ))";

// Echo $ sqlcommand;

MySQL (the best combination with PHP) _ query ($ sqlcommand );
MySQL (the best combination with PHP) _ 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 (as the mainstream development language )");
// Print_r ($ _ COOKIE );
?>

In this way, automatic login is enabled.

Of course, this is not enough. we also need to block users in php (as the mainstream development language) BB from modifying account information and registering new users. for example, if you want to modify registration, you can modify

PHP (create the .ucp_register.html template under the current development language "bb3rc2stylesprosilveremplate". delete the content. add this

Related Article

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.