Codeigniter整合Discuz同步登录的方法

2012 年 12 月 23 日5760

Ucenter整合Discuz同步登录

或:在安装Discuz之后,会有一个UCenter,并且已建立好一个应用,可以用这个,日前未试过同步登录是否可行。

Codeigniter整合Ucenter同步登录

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

1、在康盛网站http://http://www.zjjv.com//senz.com/downloads/install/ucenter下载ucenter源码包

2、解压后,将uc_client文件夹复制到CI根目录。同样,在advanced/examples复制api文件夹、include文件夹、config.inc.php到CI根目录。

3、在UCENTER管理中心添加一个应用,

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 [L]

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);

0 0