3

我想知道在另一个站点登录后是否可以自动登录moodle?我尝试使用 curl,但它似乎并没有真正起作用。

这是我的测试代码:

//set POST variables
$url = "http://moodlesite.com/login/index.php";

$fields = array(
    'username' => 'username',
    'password' => 'password'
);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

我注意到在moodle登录到系统后,他们再次将其重定向到http://moodlesite.com/login/index.php?testsession=userid,在这种情况下他们需要cookies。

4

2 回答 2

8

您可以创建一个自定义页面以登录到moodle。

该页面的代码。

<?php
require('config.php');
$name=$_REQUEST['name'];
$password=$_REQUEST['password'];
$dashboard = $CFG->wwwroot;
$user = authenticate_user_login($name, $password);
if(complete_user_login($user))
{
echo "login";
}
else
{
   echo "not login";
}



?>

创建该页面后,您可以传递名称和密码进行登录。

于 2013-11-08T12:31:06.270 回答
1

Not like that, Moodle needs to setup a session in your browser in order for you to be logged in. In general your requirement sounds strange - what exactly are you trying to achieve?

If you'd prefer to avoid your users logging in twice, you would be better implementing some sort of single sign on system:

If none of those suit, you can also create your own authentication plugin. See Authentication plugins in Moodle docs and lib/authlib.php for details.

于 2013-10-15T15:02:46.370 回答