Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

karankia's avatar

Unable to get MoodleSession Id in a Cookie using Guzzle HTTP but able to get it with Postman

I am making call to moodle Web Service to login a user. For my project I do need to get moodle Session Id. When I make a call to the Moodle Auth Page I do see that Session ID is created and set in the Cookie header of Postman like below https://i.stack.imgur.com/4TGM2.png https://i.stack.imgur.com/PNNNa.png But when I try to implement the same procedure using Laravel I do not see any value of the Moodle Session in my browser cookies, there is a value but its from another page. https://i.stack.imgur.com/nHfBx.png Below Is my code

MOODLE_URL="https://fcp.dev.muhc.mcgill.ca/login/auth.php"

public function PostApi($url, $body): string
{
    try {

        $jar = new CookieJar();
        $client = new Client(['verify' => false, 'cookies' => true]);
        $response = $client->post( $url, ['headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded'],'form_params'=> $body]);
        return $response->getBody()->getContents();

    } catch (BadResponseException $e) {
        return $e->getMessage();
    }

}
$body = ['username' => $userNameString, 'password' => $userNamePassString, 'token' => $getToken->token];
        return $callFedAuth->PostApi(env('MOODLE_URL'), $body);

As you can see that I am using a Cookie Jar as mentioned in the Guzzle documentation but still I dont get any info inserted in my Cookie. Any help or any ideas would be great.

0 likes
0 replies

Please or to participate in this conversation.