How to set the maximum number of redirects to follow in a Guzzle request in PHP?

To set the maximum number of redirects to follow in a Guzzle request in PHP, you can use the allow_redirects option in the request configuration. Here's an example:

use GuzzleHttp\Client; $client = new Client(); $response = $client->request('GET', 'http://example.com', [ 'allow_redirects' => [ 'max' => 5, // Set the maximum number of redirects to follow // You can also customize other redirect options, such as 'strict', 'referer', 'protocols', etc. ], ]); $body = $response->getBody()->getContents();

In the example above, max option is set to 5, which means that Guzzle will follow a maximum of 5 redirects. You can adjust this value to your desired limit.

Note: By default, Guzzle will follow a maximum of 5 redirects if you don't specify the allow_redirects option.