Website Integration Ucenter Detailed process

Source: Internet
Author: User
Tags pconnect set cookie setcookie

Recently, the company projects to use SNS, in the specific solution above because the project by a strong outsourcing company to do, so there is no commercial solution. But I have been more optimistic about Hong sing products, because the outsourcing company to take charge of the project, although the previous use of SNS also in many, SNS has also been the plug-in development and integration, but really did not thoroughly ucenter flexible application.                     This does not look for some data research. I heard that recently Uchome are 2.0, it seems that the first half of the use of 1.5 of it ... Wuhan Baidu Company

PS: Feel the blog inside add a picture to decorate a bit or very good-looking ....

Original address:? p=44

The first step: Download the installation Ucenter, here is not detailed, online a lot of tutorials

1. Download Ucenter


2. Installing Ucenter
Graphic installation tutorial:? tid=897809

Second step: Open the Download Ucenter folder in the Advanced folder, here is the interface file, the document is the interface API description, examples folder is some examples of use, according to these examples will quickly grasp the effect you want to achieve, UC_ The client is an interface file.

Step three: Copy the Include folder from the examples folder to your site root directory, which contains a file called db_mysql.class.php, which is the class that connects the database.

Fourth step: Copy the Uc_client folder to your website root directory, Uc_client said the interface code, now the root directory already has the include and uc_client two folders.

Fifth step: Copy the config.inc.php in the examples folder to the root of your site, which is the configuration file for configuring Ucenter

Sixth step: Configure the various parameters of the config.inc.php, the parameters have been written in detail

<?php

Define (' Uc_connect ', ' MySQL '); How to connect ucenter: Mysql/null, default is empty when Fscoketopen ()
MySQL is a directly connected database, for efficiency, it is recommended to use MySQL

Database dependent (when MySQL is connected and no uc_dblink is set, the following variables need to be configured)
Define (' uc_dbhost ', ' localhost '); Ucenter Database Host
Define (' Uc_dbuser ', ' root '); Ucenter Database user Name
Define (' UC_DBPW ', "); Ucenter Database Password
Define (' Uc_dbname ', ' ucenter '); Ucenter database name
Define (' Uc_dbcharset ', ' GBK '); Ucenter Database Character Set
Define (' Uc_dbtablepre ', ' ucenter.uc_ '); Ucenter database table prefixes

Communication-related
Define (' Uc_key ', ' 123456789′ '); Communication key with Ucenter, to be consistent with Ucenter
Define (' Uc_api ', '); Ucenter URL address, which is dependent on this constant when calling the Avatar
Define (' Uc_charset ', ' GBK '); Ucenter's character Set
Define (' Uc_ip ', "); Ucenter IP, set this value when Uc_connect is not in MySQL mode and the current application server resolves a domain name problem
Define (' Uc_appid ', 1); ID of the current app

Application database connection parameters used by ucexample_2.php
$dbhost = ' localhost '; Database server
$dbuser = ' root '; Database user Name
$DBPW = "; Database Password
$dbname = ' Ucenter '; Database name
$pconnect = 0; Database Persistent Connection 0 = off, 1 = Open
$tablepre = ' Example_ '; Table name prefix, install multiple forums in the same database please modify here
$dbcharset = ' GBK '; MySQL character set, optional ' GBK ', ' big5′, ' utf8′, ' latin1′, left blank for set according to forum character set

Sync Login Cookie Settings
$cookiedomain = "; Cookie Scope
$cookiepath = '/'; Cookie Action Path

Where the communication key needs to go to the already installed Ucenter system to fill in

Login Ucenter after clicking on the left side of the application management, the right to add a new application, choose a custom installation, fill in the application name, the URL of the application (that is, the directory of config.inc.php files, usually placed in the root directory, is filled), communication key you like to fill, the application type selected other, Turn on sync Login to receive notifications

The Ucenter configuration information for an application is generated after the commit, and the configuration information is replicated to the config.inc.php corresponding to this section of the information

Configuration information This way, it's over, and it's officially integrated ucenter.

Seventh Step: Add the following code to the place where you need to use the Ucenter (I add to the common.php contained in all files)

Include_once ' config.inc.php ';
Include_once ' include/db_mysql.class.php ';
$db = new Dbstuff;
$db->connect ($dbhost, $dbuser, $DBPW, $dbname, $pconnect);
Unset ($dbhost, $dbuser, $DBPW, $dbname, $pconnect);
Include_once ' uc_client/client.php ';

As a result of integration, you just need to join the interface functions you need to communicate to Ucenter, the following only describes synchronous registration, login, exit, other functions can refer to the API

Synchronous Login BBS (this version I have improved to, did the automatic activation):

List ($uid, $username, $password, $email) = Uc_user_login ($_post[' username '), $_post[' PW ']);

Enter the user's user name and password here

Setcookie (' auth ', ",-86400);
if ($uid > 0) {
if (! $db->result_first ("SELECT count (*) from {$tablepre}members WHERE uid= ' $uid '")) {
Determines whether the user exists in the user table, does not exist, jumps to the activation page
$auth = Rawurlencode (Uc_authcode ("$username/T". Time (), ' ENCODE '));
Echo ' You need to activate this account in order to enter the application <br><a href= "bbs/logging.php?example=register&action=activation& Auth= '. $auth. ' > Continue </a> ';
$tmp = $db->query ("SELECT count (*) from {$tablepre}members where uid=". $uid);
if (! ( $userNotexist = $db->result ($tmp))) {
$sql = "INSERT INTO {$tablepre}members (Uid,username,email,groupid,timeoffset) VALUES ({$uid}, ' {$username} ', ' {$email} ', ' 10′, ' 9999′) ';
$sql = $db->query ($sql);
$sql = "INSERT INTO {$tablepre}memberfields (UID) VALUES ({$uid})";
$sql = $db->query ($sql);
}
}

User login success, set cookies, encrypt directly with Uc_authcode function, users use their own functions
Setcookie (' auth ', Uc_authcode ($uid. ") /t ". $username, ' ENCODE '));
Generate code for synchronous logins
$ucsynlogin = Uc_user_synlogin ($uid);

echo $ucsynlogin. ' <br><a href= "'. $_server[' php_self ']. '" ></a> ';

} elseif ($uid = =-1) {
Echo ' user does not exist, or is deleted ';

}
}elseif ($uid = =-2) {
echo ' wrong password ';
} else {
echo ' undefined ';
}

Synchronous registration:

Synchronous Registration Ucenter
$uid = Uc_user_register ($_post[' username '), $_post[' password '], $_post[' email ');
if ($uid <= 0) {
if ($uid = =-1) {
Echo ' User name is not legal ';
} elseif ($uid = =-2) {
Echo ' contains the words to be allowed to register ';
} elseif ($uid = =-3) {
Echo ' user name already exists ';
} elseif ($uid = =-4) {
Echo ' Email format is incorrect ';
} elseif ($uid = =-5) {
Echo ' Email is not allowed to register ';
} elseif ($uid = =-6) {
Echo ' The Email has been registered ';
} else {
echo ' undefined ';
}
} else {

Sync Login BBS
List ($uid, $username, $password, $email) = Uc_user_login ($_post[' username '), $_post[' password ']);
Setcookie (' auth ', ",-86400);
if (! $db->result_first ("SELECT count (*) from {$tablepre}members WHERE uid= ' $uid '")) {
Determines whether the user exists in the user table, does not exist, jumps to the activation page
$auth = Rawurlencode (Uc_authcode ("$username/T". Time (), ' ENCODE '));
Echo ' You need to activate this account in order to enter the application <br><a href= "bbs/logging.php?example=register&action=activation& Auth= '. $auth. ' > Continue </a> ';
$tmp = $db->query ("SELECT count (*) from {$tablepre}members where uid=". $uid);
if (! ( $userNotexist = $db->result ($tmp))) {
$sql = "INSERT INTO {$tablepre}members (Uid,username,email,groupid,timeoffset) VALUES ({$uid}, ' {$username} ', ' {$email} ', ' 10′, ' 9999′) ';
$sql = $db->query ($sql);
$sql = "INSERT INTO {$tablepre}memberfields (UID) VALUES ({$uid})";
$sql = $db->query ($sql);
}
}
User login success, set cookies, encrypt directly with Uc_authcode function, users use their own functions
Setcookie (' auth ', Uc_authcode ($uid. ") /t ". $username, ' ENCODE '));
Generate code for synchronous logins
$ucsynlogin = Uc_user_synlogin ($uid);
echo $ucsynlogin. ' <br><a href= "'. $_server[' php_self ']. '" ></a> ';

Register successful, set Cookie, encrypt directly with Uc_authcode function, user use own function
Setcookie (' auth ', Uc_authcode ($uid. ") /t ". $_post[' username '), ' ENCODE ');
Echo ' registered successfully <br><a href= '. $_server[' php_self ']. ' " > Continue </a> ';
}

Synchronous exit:

Synchronous Exit BBS
Setcookie (' auth ', ",-86400);
Generate code for synchronous exit
$ucsynlogout = Uc_user_synlogout ();
echo ". $ucsynlogout. ' <br><a href= "'. $_server[' php_self ']. '" ></a> ';



Maybe some code will be wrong or wrong, so the above is only for reference, if there is no understanding, please reply or email me

Website Integration Ucenter Detailed process

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.