Problem Description
I was wondering is it possible to automatically login to moodle after loging-in in aonther site? I tried to use curl but it seems not really working.
This is my testing code:
//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);
I notice that after moodle login to the system, they redirect it again to http://moodlesite.com/login/index.php?testsession=userid and they need cookies it this case.
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?