codeigniter整合ucenter1.6雙向通訊的解決辦法_php執行個體

來源:互聯網
上載者:User

用codeigniter開發一個子網站,之後想和原來的論壇進行同步,包括同步登陸和雙向通訊

先裝好ucenter,然後建立一個other的應用,把產生的程式碼拷出來,建立一個config.ini.php到你的uc_client,ucenter會產生一個yourdomain.com/api/uc.php的請求,/api/uc.php不需要填寫,要保證ucenter請求正確位置,才能做到雙向通訊

把uc_client複製到你的網站,目錄可以自己定,就根目錄吧。如果你把api目錄放到uc_client目錄低下,那麼應用的請求路徑yourdomain.com/uc_client,如果api也放在根目錄請求地址uc_client可以去掉

建一個libraries/Ucenter.php內容是

複製代碼 代碼如下:
<?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);
    }
}
?>

具體要反回哪些函數,可以在上面代碼加上,可以開啟uc_client/client.php看,可以加上你需要的函數,返回即可。

調用方法:

複製代碼 代碼如下:
$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)){
    //產生同步登入的代碼
    $ucsynlogin = $this->ucenter->synlogin($uid);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.