Solution for codeigniter to integrate ucenter1.6 two way communication

  • 2021-06-28 12:11:20
  • OfStack

Develop a subsite with codeigniter and then want to synchronize with the original forum, including synchronous login and two-way communication

First install ucenter, then create a new other application, copy the generated code, create a new config.ini.php to your uc_client, ucenter will generate an yourdomain.com/api/uc.php request, /api/uc.php does not need to be filled in, to ensure that the ucenter request is in the correct location for bidirectional communication

Put uc_client copies to your website, the directory can be determined by yourself, just the root directory.If you place the api directory in uc_The client directory is low, so the application request path yourdomain.com/uc_client, if api is also placed in the root directory request address uc_client can be removed

Create an libraries/Ucenter.php content

<?php
class Ucenter {
    function __construct() {
        require_once FCPATH . './api/uc_client/config.inc.php';
        require_once FCPATH . './api/uc_client/client.php';
    }
    function getUserId() {
        return $this->_uid;
    }
    function getUserName() {
        return ucwords(strtolower($this->_username));
    }
    function login($username, $password) {
        return uc_user_login($username, $password);
    }
    function synlogin($uid) {
        return uc_user_synlogin($uid);
    }
    function login_out() {
        return uc_user_synlogout();
    }
    function regediter($username, $password, $email) {
        return uc_user_register($username, $password, $email);
    }
}
?>

To specify which functions to revert to, you can add them to the code above and open uc_client/client.php Look, you can add the function you need and return.

Call method:

$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->library('ucenter');
list($uid, $username, $password, $email) = $this->ucenter->login($username, $password);
if(!empty($uid)){
    // Generate code for synchronous login 
    $ucsynlogin = $this->ucenter->synlogin($uid);
}


Related articles: