开发者

Using Cometchat & Rails together - is this possible?

I hope someone can advise / direct / shed some light on :

i have a rails application that uses Authlogic for authentication. i would like to incorporate cometchat into thi开发者_如何学编程s application - (in reality any chat IM would do - but cometchat seemed to fit nicely because ajax-im does not like windows)

The environment is the following : The rails app is running on a windows machine - and will be available to the local network (no internet) So to be able to use cometchat - i am running the WAMP server.

Into the nitty gritty of php(which i dont know well at all)

authlogic keeps my user session for me.

but for cometchat to work i need to pass the getUserID function the current user. (comet chat assumes that there is a php session variable - but i dont have this with rails)

So how can i pass the rails session user to the getUserID function.

the function looks like this: *function getUserID() { $userid = 0;

if (!empty($_SESSION['userid'])) {
    $userid = $_SESSION['userid'];
}
return $userid;

}*

the next function has to do with the friends list - but im sure this can be solved with sql inside the php page once i have the current user.

Again - all and any guidance is welcome here. Even if it means an alternate chat solution.

Many thanks in advance.


akza,

You can store the userid(numeric, non-zero, unique preferably the primary key from your users table) of currently logged-in user in a cookie say 'userid_for_cometchat'
and can access it as $_COOKIE['userid_for_cometchat'] in PHP

So your getUserID() should look like:

function getUserID() {
     $userid = 0;
     if (!empty($_COOKIE['userid_for_cometchat'])) {
            $userid = $_COOKIE['userid_for_cometchat'];
     }
     return $userid;
}

You need to create this cookie on login and make sure to destroy it on logout.

This should work well.

CometChat Support team is real great at doing such stuff and they have performed a lot of custom modifications for me and I'm really satisfied by their job.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜