It's possible that the cookies are not being properly formatted when passed in the headers. Try converting the cookies array to a string using the http_build_query function before passing it in the headers. Here's an example:
$cookies = http_build_query($authResponse->cookies());
$userDetailsResponse = Http::withHeaders([
'Cookie' => $cookies,
])->get('https://www.example.com/profile.php');
If that doesn't work, you can try manually setting the cookies in the client's cookie jar using the withCookie method. Here's an example:
$client = Http::withHeaders([
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
])->withOptions([
'cookies' => true,
]);
$authResponse = $client->asForm()->post('https://www.example.com/login.php', [
'email' => '[email protected]',
'password' => '12345678',
]);
$userDetailsResponse = $client->withCookie($authResponse->cookies())->get('https://www.example.com/profile.php');
This sets the cookies option to true when creating the client, which enables the cookie jar. Then, the withCookie method is used to manually set the cookies from the authentication response.