2

Good day everyone. I'm currently programming in Moodle. Since I haven't got any answers yet in their forums I will have to ask it here because I really need help badly. How can my cURL bypass Moodle login page?

    $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);

Given this code, I have successfully logged in as admin but the problem is that I'm still stuck in the login page instead of proceeding to the url (http://127.0.0.1/mod/quiz/report.php?q=4&mode=analysis) which is supposed to be my target. How am I suppose to bypass the login page? Any help would be greatly appreciated. Thanks!

POGI
  • 21
  • 1
  • 2
  • Do you ever execute the connection to the login page? –  Sep 17 '11 at 12:15
  • In a way I did because on the upper left I saw I successfully logged in but I remain stuck in the login page. – POGI Sep 17 '11 at 12:58

1 Answers1

0

If you'd like to use moodle with PHP, you should not use cURL to work on the pages, but instead use the Moodle API. If for any reason you still want to use the webpages, you should at least use the Moodle API to authenticate. This gives you a session-token, with which you may access subsequent pages.

Lars
  • 5,757
  • 4
  • 25
  • 55
  • Thank you for the reply! Yeah I been thinking about using Moodle API but really I have little time remaining, is there a fast way to learn Moodle API? – POGI Sep 17 '11 at 13:52
  • Never used it, but it looks pretty standard: http://moodle.org/mod/forum/discuss.php?d=151921 – Lars Sep 17 '11 at 22:42