PHPBB3 with the website, to achieve the login station at the same time login forum _php Tutorial

Source: Internet
Author: User
Because of the reason for the work. This was used, so we studied it.

The main idea is to simulate cookies. Insert the user ID and a sessionid into the cookie first, and then insert the SessionID, and the user ID into the sessions table in the database, and if you open the forum, the system will verify that the cookie information is the same as the information in the database. If the same words can be implemented automatically login. The main code of the login is as follows:

Get 32-bit random SessionID
Initialize each of the values
$Session _testid=create_sess_id (32);
$SessionIp =192.168.0.100;
$cookie _path=/;
$cookieName =php (as the current mainstream development language) bb3_1w36a;
$userBrowserInfo = $_server["Http_user_agent"];
$userIpAdd =$_server["REMOTE_ADDR"];

Get the user name and password for the form
$cmd _username=$_post["username"];
$cmd _password=$_post["Password"];
First with the CMS system table verification, if passed. Querying the corresponding user name the ID in the BBS user table

$link =mysql (the best combination of PHP collocation) _connect ("localhost", "root", "");
MySQL (and PHP collocation of the best combination) _select_db ("CMS");
$selectUid = "Select user_id from Bbs_users where username= $cmd _username";
$uidResult =mysql (the best combination with PHP) _query ($selectUid);
$userId =null;
while ($row 1 = mysql (best combination with PHP) _fetch_array ($uidResult, MySQL (best combination with PHP) _num))
{
$userId = $row 1[0];
}
Echo $userId;
MySQL (the best combination of PHP collocation) _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);

Inserting session information into PHP (as the current mainstream development language) B_sessions table
$link =mysql (the best combination of PHP collocation) _connect ("localhost", "root", "");
MySQL (and PHP collocation of the best combination) _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 current mainstream development language)) ";

Echo $sqlcommand;

MySQL (the best combination of PHP collocation) _query ($sqlcommand);
MySQL (the best combination of PHP collocation) _close ($link);


Generate a 32-bit random number
function create_sess_id ($len =32)
{
Gets the current time in microseconds
List ($u, $s) = EXPlode (, microtime ());
$time = (float) $u + (float) $s;
Generate a random number
$rand _num = rand (100000, 999999);
$rand _num = rand ($rand _num, $time);
Mt_srand ($rand _num);
$rand _num = Mt_rand ();
Produce SessionID
$sess _id = MD5 (MD5 ($TIME). MD5 ($rand _num));
Intercept a SessionID that specifies the length required
$sess _id = substr ($sess _id, 0, $len);
return $sess _id;
}
Header ("location:http://192.168.0.100/bbs/index.php (as current mainstream development language)");
Print_r ($_cookie);
?>

In this way, you can implement automatic login.

Of course, only these are not enough, but also to block PHP (as the current mainstream development language) BB Users modify account information and register new users. For example, to modify the registration, you can modify

PHP (as the current mainstream development language) Bb3rc2stylesprosilveremplate this directory below. ucp_register.html module. Delete the contents of the inside. Add this.

In this way, when the user points to register, read the terms after the point of registration, will jump to the registration page on the site. The same thing about modifying information:

My approach does not unify the user table. But each has its own user system.

When registering users on the site, insert user information into the users and User_group tables of the BB Database for PHP (the current mainstream development language). Remember, you have to look at the group.

permissions, insert the appropriate things, otherwise you may not be able to log in, do not change the message, can not read the section and other issues. This part is long and simple, the code is saved. Mostly logged in.

http://www.bkjia.com/PHPjc/508891.html www.bkjia.com true http://www.bkjia.com/PHPjc/508891.html techarticle because of the reason for the work. This was used, so the study was done. The main idea is to simulate cookies. Insert the user ID and a sessionid into the cookie before you go to the sessions table in the database ...

  • 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.