Third-party programs perfectly integrate the UC user center of phpwind8-tutorial + p8

Source: Internet
Author: User

No matter how phpwind goes, we will always support it !!This tutorial analyzes how to integrate the UC user center of phpwind and provides the complete p8uc integrated interface package after the separation from P8.

P8uc role:
The UC communication principle of P8 is basically the same as that of other programs, mainly to facilitate the integration of user and intra-site synchronization information, such:
Synchronous logon, synchronous registration, and points synchronization.

As phpwind has not provided tutorials and development documents, many people do not know whether phpwind has UC or how to use it.
The answer is that some of phpwind's UC projects will share their research results with you.
For the convenience of secondary development and integration of p8uc, this tutorial was created by edoog Weike. edoog became the first program to integrate p8uc in phpwind history.
Edoog separates the p8uc standalone UC interface package from the original phpwind program. This chapter provides a tutorial for you to download and study.
Note: This tutorial and p8uc integration independent interface package can be universal, such as integration with the Dede program and php168 program.

Someone has to ask, isn't the phpwind program capable of Integrated Traffic consolidation? Why is UC still used? Please refer to the following cutting-edge

As early as phpwind7.5, you already have built-in UC. It is not clear that the functions are not implemented until after P8 is estimated to be relatively mature. The early pass of UC is eliminated, pass integration only supports one-way integration and synchronization, which means that third-party registration can only be performed on the forum registration page. After the registration is successful, jump back to the original click page through the address, which looks very tired. The emergence of UC enables two-way synchronization for registration and login. Users can register and log on to the third-party program page. After registration and login, the third-party program notifies UC, and UC then notifies other third-party programs to form two-way synchronization, users do not need to jump between the main site and a third-party website.

Can I use ucenter instead?
Phpwind8 has its own UC, and one thinks it is unnecessary to integrate another UC. Recently, someone has published a ucenter integrated with P8 in this forum, also known
The uc_client folder is useless to delete. It is speechless... Today, I will make the uc_client folder take effect.

Comparison between p8uc and ucenter Functions

P8uc communication principle
The main site of the P8 forum is the server, and other third-party programs are set as clients,
The following flowchart provides a deeper understanding of the p8uc communication process.

Analyze communication files and folders
Assume that other third-party programs are clients.
This is a key step. We need to separate the communication interface files mixed in P8 so that other programs can be easily integrated and used.
Separate and sort out the pw_api.php file, pw_client folder (uc_client folder, the client may be renamed with other UC),/API/pw_api folder.

It is analyzed that P8 communication is based on the/pw_api.php file, so we can start with/pw_api.php.
The/pw_client folder is the client-side Notification Server program.
The/API/pw_api folder indicates the client program notified by the server.

The above analysis and Separation complete the client independent interface file, simple!

Practical modification of UC interface program Integration
After the above files are separated, we now modify the integration program. It is estimated that we can complete Dede's P8 UC integration package development in half a minute.
There are many synchronization integration projects. I only select synchronous registration and synchronous login as the reference modification example. The modification methods for other synchronization projects are the same.
The following describes how phpwind8 is used to modify the server and edoog Weike client, and is applicable to other Dede and php168 programs.
1. Communication access pw_api.php

First, modify the/pw_api.php file. The website and database information referenced in the pw_api.php file is P8. We can replace this information
The program configuration and database link information you want to integrate. The modification is as follows:

Note that the following explanation requires PHP knowledge.

Copy code
  1. <? PHP
  2. Error_reporting (0 );
  3. Define ('P _ W', 'admincp ');
  4. Include ('./common. php ');
  5. Define ('R _ P', s_dir .'/');
  6. Define ('d _ P', R_p );
  7. Require_once (s_dir. '/API/pw_api/security. php ');
  8. Require_once (s_dir. '/API/pw_api/pw_common.php ');
  9. Require_once (s_dir. '/API/pw_api/class_base.php ');
  10. $ API = new api_client ();
  11. $ Response = $ API-> Run ($ _ post + $ _ Get );
  12. If ($ response ){
  13. Echo $ API-> dataformat ($ response );
  14. }
  15. ?>

Copy the code

  1. Include ('./common. php ');

In the above sentence, the website configuration data of edoog is loaded, and the website configuration data of other programs is loaded.

Copy the code

  1. Define ('R _ P', s_dir .'/');

In the above sentence, s_dir is the edoog website path, and other programs change its website PATH variable.
Haha above, UC communication access is completed

2. synchronous registration-the client notifies the server
During client registration, such as Dede registration, load the P8 client class and configure the database link. In the preliminary test, you can directly write configuration information such as the database.
Some of the configuration information, such as the key, will be explained later.

2.0 load client codeCopy code

  1. Define ('P _ W', 'admincp ');
  2. Require_once (s_dir. '/API/pw_api/security. php ');
  3. Require_once (s_dir. '/API/pw_api/pw_common.php ');
  4. // Application p8uc configuration information
  5. Define ('uc _ dbhost', 'localhost'); // P8 Forum Database Host
  6. Define ('uc _ dbuser', 'root'); // User Name Of The P8 Forum Database
  7. Define ('uc _ dbpw ', 'root'); // password of the P8 Forum Database
  8. Define ('uc _ dbname', 'phpwind '); // P8 Forum Database Name
  9. Define ('uc _ dbcharset', 'gbk'); // P8 Forum database Character Set
  10. Define ('uc _ dbtablepre', 'PW _ '); // P8 Forum database table prefix
  11. Define ('uc _ dbconnect ', '0'); // P8 Forum database persistent connection 0 = disabled, 1 = Enabled
  12. Define ('uc _ key', 'df5gd8g7sdf54sd8'); // The Communication Key of the P8 forum, which must be consistent with that of the P8 forum.
  13. Define ('uc _ API ', 'HTTP: // localhost/PW'); // The URL address of the P8 forum, which depends on this constant when calling the Avatar
  14. Define ('uc _ charset', 'gbk'); // the character set of The P8 Forum
  15. Define ('uc _ ip', '127. 0.0.1 '); // ip address of the P8 Forum
  16. Define ('uc _ appid ', '2'); // the ID of the current application
  17. @ Include_once (s_dir. '/pw_client/uc_client.php ');

The above code is linked to the server and configured. In actual applications, you can write the code to the integration for secondary reference.

After the configuration, load it into the code of the actual registration program for judgment.

2.1 The following program checks whether the UC user name has been registered

Open the/pw_client/uc_client.php file and you will find many interfaces for synchronizing application projects.

Copy the code

  1. Function uc_check_username ($ username ){
  2. $ ARGs = func_get_args ();
  3. Return uc_data_request ('user', 'checkname', $ ARGs );
  4. }

This is the function I added to check whether the user exists.

Assume Registration Information
User name test user
Password 123456


Copy code
  1. $ Checkuser = uc_check_username ('test user ');
  2. If ($ checkuser = 1 ){
  3. Return 1;
  4. } Elseif ($ checkuser =-1 ){
  5. Return-1;
  6. } Else {
  7. Return-3;
  8. }

If the return value is 1, registration can be performed. Otherwise, registration can be performed temporarily.

2.2 registered UC users

The registered user's UC client has built-in
Use method to copy code

  1. Uc_user_register ('test user', MD5 (123456), '2017 @ ');

Note: The synchronous registration password must be MD5

Congratulations, you have completed synchronization registration.

3. synchronous Login
You have learned how to use the synchronization registration modification in the previous section. Next, modify the synchronization logon.
Synchronous Logon
1. The client notifies the server
2. The server notifies the client
These two modifications, synchronous login is one of the simplest ones

3.1 synchronous login-client Notification Server

Similarly, when the client notifies the server to modify the content, it must intercept the previous section in the client program.2.0 load client codeTo use the UC client functions.
Assume the logon information
User ID 2
Password 123456

Copy code
  1. $ User_login = uc_user_login (2, MD5 (123456), 1 );
  2. Return $ user_login ['synlogin'];

The above Code 2 is the user ID, the password is also MD5, And the next 1 refers to the use of uid communication, you can refer to the official phpwind annotations.
After logon, the system returns the array $ user_login ['synlogin'], which must be output on the page. You cannot log on synchronously without outputting $ user_login ['synlogin.

Synchronous logon-the client notifies the server that the modification has been completed. Now the client has notified the server, and other programs have logged on synchronously.

3.2 synchronous logon-server-side notification Client
The previous section describes how to notify the server by a third-party client program. The following section describes how the server notifies the third-party client.
Assume the logon information
User ID 2
Password 123456
If you have logged on to the P8 forum on the server, the server will notify the service program class of the client. This refers to the/API/pw_api folder.
\ API \ pw_api \ class_user.php file. The function synlogin ($ user) function in the file is used to synchronously notify logon. Is it similar to ucenter?

Okay. Add our logon code to the synlogin function, for example, add the edoog WITKEY logon code.

Copy code
  1. Function synlogin ($ user ){
  2. Global $ timestamp, $ uc_key;
  3. List ($ winduid, $ windid, $ windpwd) = explode ("\ t", $ this-> base-> strcode ($ user, false ));
  4. Header ('p3p: Cp = "Cura ADMA Deva psao psdo our bus uni pur int DEM sta pre com nav OTC Noi DSP cor "');
  5. Include_once s_dir. '/class. user_login.php ';
  6. $ Member = getmember ($ winduid );
  7. If ($ member ){
  8. $ Windid = $ Member-> username;
  9. }
  10. $ Suserlogin = new userlogin ($ wind ID, '', 3600*24 );
  11. $ Suserlogin-> setcookies ();
  12. }

Copy the code

  1. Include_once s_dir. '/class. user_login.php ';
  2. $ Member = getmember ($ winduid );
  3. If ($ member ){
  4. $ Windid = $ Member-> username;
  5. }
  6. $ Suserlogin = new userlogin ($ wind ID, '', 3600*24 );
  7. $ Suserlogin-> setcookies ();

This is the edoog VIP code part, which can be replaced with the Dede login code.

Synchronous logon-the server side notifies the client to complete the process ~

More simply, log out synchronously.
This item also has
1. The client notifies the server
2. The server notifies the client
You can modify it just like the above method.

The modification of the program has been explained, and it may be difficult for beginners to understand. It is recommended that you read the ucenter development manual in the same way. Apply the client program I provided.

Practical operations integrate UC applications
In the previous section, we talked about modifying program integration, but the applications on both sides are not set to enable the synchronization application, so it is not successful yet,
Next, I will explain how to integrate the UC application in the last part.
In the background tutorial, we take edoog Weike integration as an example. The previous sections show whether the code is too big. The full picture later makes learning easier.

Phpwind8 background integration settings

Add an application in the phpwind8 background

Phpwind8 background point Synchronization

Edoog background integration settings

1. The phpwind8 UC server is phpwind8 itself. The server has no independent programs and only the independent programs separated by the client. Please do not understand the error.

2. A server bug was found during development and testing of the client program. The server points synchronization notification bug will not be noticed by the server points synchronization. The client is normal and does not know whether the current P8 version has been corrected.

3. Download my P8 UC client, dedicated to third-party client programs.

4. usage tips because most programs use ucenter. when integrating P8 UC, you only need to add a judgment in their programs so that the previous ucenter integration can be retained and the P8 UC integration can be added, the integration code directly copies the program in the ucenter client, and it's easy to integrate P8 UC!

The following P8 UC client program edoog has been improved and enhanced. Download and decompress the program to the root directory of other programs, such as Dede and php168, then, it is very easy to modify and debug according to my tutorial. I wish you a pleasant integration !.

Download the P8 UC client GBK
 Phpwind8 (28 K) Downloads: 232

Download the P8 UC client utf8

 Phpwind8 (28 K) download times: 103

User center Instruction Manual:

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