misagh ahmadi
misagh ahmadi

Reputation: 89

Laravel - Guzzle 7 : How get effective url in laravel?

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

Answers (2)

misagh ahmadi
misagh ahmadi

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

azibom
azibom

Reputation: 1944

Hi
You can do sth like it

$client = new \GuzzleHttp\Client(['allow_redirects' => ['track_redirects' => true]]);

$response = $client->request('GET', 'http://test.com');

If you want to read more about the "track_redirects" look at this link

Upvotes: 2

Related Questions