ThinkPHP3.0 Integration UCenter1.6 (II.)

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Because these days there is a project to delivery, so has been very busy, no time to thinkphp3.0 integrated ucenter1.6 after the subsequent writing, today finally a little time to integrate the TP UC to complete, so that everyone waiting, really embarrassed!

Previously published an article thinkphp3.0 integration ucenter1.6 get everyone's approval, then some netizens reflect or can't integrate, then summed up a bit, found that I did not say too clearly last time, The final reason is not to uc.php the path in all of the changes, we look for the config.inc.php inside the uc.php, and modify the name of our own configuration file config_ucenter.php, and modify the corresponding path! So you can communicate successfully!

If the unsuccessful children's shoes can give me a message, or directly consult me, when I am not busy will reply to everyone!

All right, now let's get to the formal integration! My idea is to ucenter the API method provided by the package, so that our program looks more clean and tidy! First, we first create a new folder in the Lib directory, and name it: Service. The function of this folder will be explained to you. Then the service inside the establishment of our own class, to facilitate the communication with UC, new php file, file name: UcService.class.php,

Class name Ucservice, we implement the Ucenter operation in the class. To operate the Ucenter API, first we have to import the corresponding file, I believe you have thought, the first is ucenter configuration file: config_ucenter.php, the second is my program and Ucenter communication client.php file. To import these two files, we add a constant to the index.php entry file to define our physical and directory.

Physical and path of project

Define (' Doc_root_path ', RTrim (DirName (__file__), '/\\ '). Directory_separator);

Then we define a constructor in UcService.class.php to import our two files,

Public Function __construct ()
{
Include_once (Doc_root_path. ' conf/config_ucenter.php ');
Include_once (Doc_root_path. ' uc_client/client.php ');
}

Ok! believe that children's shoes have completed the above steps, we will write the corresponding code to achieve and Ucenter synchronization, first of all, we first to complete the registration code.

User registration This method is UcService.class.php

Public Function Register ($username, $password, $email)
{
$uid = Uc_user_register ($username, $password, $email);
if ($uid <= 0) {
if ($uid = = 1) {
Return ' username illegal ';
ElseIf ($uid = = 2) {
Return ' contains words that are not allowed to be registered ';
ElseIf ($uid = = 3) {
Return ' username already exists ';
ElseIf ($uid = = 4) {
Return ' Email format error ';
ElseIf ($uid = = 5) {
Return ' Email does not allow registration ';
ElseIf ($uid = = 6) {
Return ' The email has been registered ';
else {
return ' undefined ';
}
else {
Return Intval ($UID);
}
}

This function is Ucenter registration verification, as long as we are in the program instance of this class, use this function to be able to conduct and Ucenter communication authentication registration.

So how do we use it?

First of all, my registration file is Http://www.ttedu.com.cn/Register/teach, that is, in your program directory, lib/action/home/under a Register.class.php file, We open this file, if not please create this file, my directory is grouped under the home is a grouped name directory, if not configured child shoes please directly in the action directory to create, this class to inherit action Oh! Then we create a Teach method function in the class, Used to display a registered page.

We then create a new function that handles the data submitted by the Teach method function and joins the database! This is the main one!

Public teach () {

$this->display ();

}

Public Function Regdo () {

if ($this->ispost ()) {
if (!$_request[' username '] | | | |!$_request[' email ') | | |!$_request[' password ']) {
Exit (' data invalid. ');
}
$nick = $_request[' username '];
$email = $_request[' email '];
$PW = Trim ($_request[' password '));

This class needs to be configured in the conf/config.php Oh, a while below will be mentioned!
$ucService = new Ucservice;
$uid = $ucService->register ($nick, $PW, $email);
Successfully registered to UC
if (!is_string ($uid)) {
$send _email = false;
$is _verifyed = 1;
Register locally
$uModel = D (' Auser ');
$data [' user_id '] = $uid;
$data [' nick '] = $nick;
$data [' email '] = $email;
$data [' password '] = MD5 ($PW);
if ($uModel->add ($data)) {
$this->success ("Registered success!") "," __app__/");
}else{
$this->error ("Registration failed!) ");
}
}else{
Exit ($UID);
}

}
}

After the local registration, children's shoes can directly write your program logic code, the implementation of this step, we have to add a sentence in the conf/config.php,

' App_autoload_path ' => ' @ Service ',

The meaning of this sentence is to tell thinkphp, we are programmed to automatically import action below the service directory in the file, if not imported, in our Regdo will be an error! will be prompted not to find the Ucservice class, Now let's test if we can register successfully?

We open Http://www.ttedu.com.cn/Register/teach fill in username, password, email, submit! ok! program prompts us to register successfully! Then we go into the ucenter to see if any of the users registered successfully? I just filled in the username: Test Password: 123456 mailbox: ttedus@126.com in Ucenter User management we've seen it already. We have just registered the user, that we registered has been successful! The following is the login code! I'm so tired. I'll just pack it up in the forum! Or leave a mailbox I send to your mailbox!

ThinkPHP3.0 Integrated Ucenter Tutorial (i)

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.