2

今天是个好日子。我目前正在 Moodle 中编程。由于我在他们的论坛上还没有得到任何答案,我将不得不在这里提问,因为我真的非常需要帮助。我的 cURL 如何绕过 Moodle 登录页面?

    $ckfile = tempnam("/tmp","CURLCOOKIE");
    $ch = curl_init(http://127.0.0.1/login/index.php);

    $data = array('username' => 'admin', 'password' => 'Admin_123');

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $url = "http://127.0.0.1/mod/quiz/report.php?q=4&mode=analysis";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);

    echo $output;

    curl_close($ch);

鉴于此代码,我已成功以管理员身份登录,但问题是我仍然停留在登录页面而不是继续访问 url (http://127.0.0.1/mod/quiz/report.php?q= 4&mode=analysis) 这应该是我的目标。我该如何绕过登录页面?任何帮助将不胜感激。谢谢!

4

1 回答 1

0

如果您想在 PHP 中使用 moodle,则不应使用 cURL 来处理页面,而应使用Moodle API。如果出于任何原因您仍想使用网页,您至少应该使用 Moodle API 进行身份验证。这为您提供了一个会话令牌,您可以使用它访问后续页面。

于 2011-09-17T13:34:04.377 回答