<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / guzzle-redirect-history-middleware example snippets
use Spatie\GuzzleRedirectHistoryMiddleware\RedirectHistory;
use Spatie\GuzzleRedirectHistoryMiddleware\RedirectHistoryMiddleware;
/*
* First create a new instance of `RedirectHistory`
* This instance can be used after the requests to get the redirects.
*/
$redirectHistory = new RedirectHistory();
/*
* This is the default way to add a middleware to Guzzle
* default middleware stack.
*/
$stack = HandlerStack::create();
$stack->push(RedirectHistoryMiddleware::make($redirectHistory));
/*
* Let's create Guzzle client that uses the middleware stack
* containing our `RedirectHistoryMiddleware`.
*/
$client = new Client([
'handler' => $stack,
]);
/*
* Now, let's make a request.
*/
$response = $client->get($anyUrl);
/*
* And tada, here are all the redirects performed
* during the request.
*/
$redirects = $redirectHistory->toArray();