Because I need to use this for work reasons, I did some research.
The main idea is to simulate COOKIES. First insert the user ID and a SessionID into Cookies, and then insert the SessionID and user ID into the sessions table in the database. If Open the forum and the system will verify whether the COOKIES information is the same as the information in the database. If they are the same, automatic login can be achieved. The main code for the login part is as follows:
<?php
//Get 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"];
//Get the username and password of the form
$cmd_username=$_POST["username"];
$cmd_password=$_POST["password"];
//Verify with the CMS system table first, if it passes. 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='$cmd_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 into 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)
{
// Get the microseconds of the current time
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();
//Generate SessionID
$sess_id = md5( md5($time). md5($rand_num) );
//Intercept the SessionID that specifies the required length
$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 can be achieved.
Of course, this is not enough. Users in PHPBB must also be blocked from modifying account information and registering new users. For example, if you want to modify the registration, you can modify
the directory phpbb3rc2stylesprosilvertemplate In the following .ucp_register.html template page, delete the content inside and add this
<script type="text/javascript" language="javascript">
window.location='member.php';
</script>
In this way, when the user clicks to register and clicks to register after reading the terms, he will jump to the registration page on the website. The method of modifying the information is basically the same.
My approach is not to unify the user table. Instead, each has its own User system.
When registering a user on the website, insert user information into the users table and user_group table of the PHPBB database at the same time. Remember, you must look at the group,
permissions, and insert the corresponding things, otherwise you may not be able to log in. Problems such as not changing the message and not being able to read the forum. This part is relatively long and simple, so the code is omitted. It is mainly the login part.