Moodle接受来自外部站点的登录 [英] Moodle Accept Login from external site

查看:145
本文介绍了Moodle接受来自外部站点的登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将Moodle添加到我们的站点(不同的服务器,不同的子域,但相同的主域,并且服务器被设置为能够相互通信),而我们想要做的是:

We are adding Moodle to our site (different server, different sub-domain, but same main domain, and the servers are set up to be able to communicate with each other) and what we want to have it do is:

  • 用户访问主站点
  • 用户登录
  • 用户单击指向Moodle的链接
  • 用户无需重新输入信息即可自动登录Moodle
  • 如果用户添加书签或直接访问Moodle,他们仍然可以直接在此处登录

我们已经使用db auth(外部数据库身份验证)对其进行了设置,因此主站点中的帐户也适用于Moodle,我只是不知道如何让Moodle接受现有的凭据并自动将用户登录

We already have it set up using db auth (the external database authentication) so the accounts from the main site also work for Moodle, I just have no idea how to get Moodle to accept the existing credentials and automatically log the user in.

推荐答案

因此,我能够解决此问题,并认为我会分享我的解决方案,以防将来其他人遇到类似问题.

So I was able to get this resolved and thought I would share my solution in case anybody else has a similar problem in the future.

由于我们的Moodle网站和主网站位于同一个域中,因此我在主网站的登录脚本中所做的工作,因此添加了以下代码:

Since our Moodle site and main site are on the same domain, what I did was in the login script for our main site, I added the following code:

$postData = array('username' => $username, 'password' => $password);
$post = http_post_fields('http://moodle.example.com/login/index.php', $postData);
$headers = http_parse_headers($post);
foreach($headers['Set-Cookie'] as $cookie)
{
    $details = http_parse_cookie($cookie);
    foreach ($details->cookies as $name => $value)
        setcookie($name, $value, $details->expires, $details->path, 'example.com');
}

基本上,我使用http_post_fields将登录凭据发布到moodle登录脚本,尽管cURL应该也可以正常工作,解析标头以获取cookie Moodle设置,然后使用基本域而不是更具体的Moodle自己设置这些cookie.子域.如果用户具有来自更特定子域的现有cookie,则可能会导致一些问题,因此请确保删除任何名称为MoodleSession的现有cookie.

Basically, I posted the login credentials to the moodle login script using http_post_fields, although cURL should work as well, parsed the headers to get the cookies Moodle set, then set those cookies myself using the basic domain instead of the more specific Moodle subdomain. This can cause some issues if the user has an existing cookie from the more specific subdomain, so be sure to delete any existing cookie with a name of MoodleSession.

这篇关于Moodle接受来自外部站点的登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆