lanizz 发表于 2011-7-21 11:09:36

Codeigniter整合Ucenter同步登陆

本帖最后由 lanizz 于 2011-7-28 11:25 编辑

Codeigniter整合Ucenter同步登陆

说明:本地测试服务器配置开启URL重写

1、在康盛网站http://www.comsenz.com/downloads/install/ucenter下载ucenter源码包
2、解压后,将uc_client文件夹复制到CI根目录。同样,在advanced/examples复制api文件夹、include文件夹、config.inc.php到CI根目录。
      如图: =====>>
3、在UCENTER管理中心添加一个应用,得到应用id。
4、在CI根目录找到config.inc.php修改相应的配置。
5、配置好之后还是显示通信失败,是因为CI启用了URL重写,需要配置CI根目录下的.htaccess文件,添加uc_client、api、include到被忽略的列表,如下:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|ckeditor|ckfinder|uploadfile|robots\.txt|uc_client|config\.inc\.php|api|include)
RewriteRule ^(.*)$ index.php/$1
6、在到ucenter管理中心可以看到通信成功!
7、在CI建立自己的类库,如在application/ libraries下新建一个文件Mycommon.php
<?php
class Mycommon {      
      function __construct(){
                include './config.inc.php';
                include './uc_client/client.php';
      }
      
      function getUserId() {
                return $this->_uid;
      }
      
      function getUserName() {
                return ucwords ( strtolower ( $this->_username ) );
      }
      
      function login($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);                              
      }
?>
8、接下来就可以在控制器中调用
      $this->load->library(‘mycommon’);
       echo $this->mycommon->login(id);
其他的方法可自行添加,参考ucapi手册!http://www.ucapi.com/api/function.htm

#个人方法,多多指教!

yangyongjun07 发表于 2011-7-27 10:33:51

学习

erebus 发表于 2011-8-27 08:14:39

学习:victory:

lnlingyuan 发表于 2011-8-30 17:56:03

给力。。。。。

cxzlr 发表于 2012-3-27 15:33:48

给力什么呀,在实际的调用中,会有一些问题

cxzlr 发表于 2012-3-27 15:36:04

特别是数据库读写时,CI会报很多ERROR,有时,连 errors/error_php.php包含语句,都会提示路径不会。
要想这样整合,还需费得工夫。
页: [1]
查看完整版本: Codeigniter整合Ucenter同步登陆