Reputation: 89
I want to get a link from user and check it , if it redirects , we take the last url ( final redirected url ) for example if this links : goo.gl/test/123 redirects to the google.com , we take the http://google.com in Guzlle`s old versions we can get effective url , but in version 7 I didnt found any way to get this
Upvotes: 2
Views: 1797
Reputation: 89
The write Answer for list of redirected / just one url :
$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);
$response = $client->request('GET', 'shorturl.at/jvOS5');
$lastRedirect = $response->getHeaderLine('X-Guzzle-Redirect-History');
More in Document : https://docs.guzzlephp.org/en/7.0/faq.html?highlight=redirected#how-can-i-track-redirected-requests
Upvotes: 2