使用 Cometchat 和Rails 在一起 - 这可能吗?

发布于 2024-08-24 06:13:42 字数 759 浏览 1 评论 0原文

我希望有人可以提供建议/指导/阐明:

我有一个使用 Authlogic 进行身份验证的 Rails 应用程序。 我想将cometchat合并到这个应用程序中 - (实际上任何聊天IM都可以 - 但cometchat似乎很适合,因为ajax-im不喜欢Windows)

环境如下:rails应用程序在Windows机器上运行 -并且可用于本地网络(无互联网) 因此,为了能够使用 cometchat - 我正在运行 WAMP 服务器。

深入了解 php 的本质(我根本不了解)

authlogic 为我保留用户会话。

但为了让 cometchat 工作,我需要将 getUserID 函数传递给当前用户。 (comet chat 假设有一个 php 会话变量 - 但我在 Rails 中没有这个)

那么我如何将 Rails 会话用户传递给 getUserID 函数。

该函数如下所示: *函数 getUserID() { $用户ID = 0;

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

}*

下一个函数与好友列表有关 - 但我确信一旦我拥有当前用户,这可以通过 php 页面内的 sql 来解决。

再次强调 - 欢迎所有和任何指导。即使这意味着另一种聊天解决方案。

非常感谢。

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 this 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何处潇湘 2024-08-31 06:13:42

akza,

您可以将当前登录用户的 userid(数字,非零,唯一,最好是用户表中的主键)存储在 cookie 中,例如 'userid_for_cometchat'
并可以在 PHP 中以 $_COOKIE['userid_for_cometchat'] 的形式访问它,

因此您的 getUserID() 应该如下所示:

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

您需要在登录时创建此 cookie 并确保销毁它在注销时。

这应该运作良好。

CometChat 支持团队非常擅长做这些事情,他们为我进行了很多自定义修改,我对他们的工作非常满意。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文