I'm trying to get a query string in the final URL after redirection.
https://example.com/oauth/auth?user=foo&password=bar
redirects in my browser to:
https://example.com/?secret=8273761838346
I need the secret={some number} part of the final URL after redirection.
I've tried (and failed) in PHP using file_get_contents, cURL, and even the socket method. cURL returns CURLINFO with the original URL, not the final one. file_get_contents $http_response_header doesn't contain the final URL.
I've tried variations on the options you can set on the cURL call, following the slew of examples available on SO and Google searching, but none of those worked. The URL returned is always the original URL, not the final.
Has anyone ever encountered this and how did you get around it? This is probably a stupid question, but could https be the problem?
@str, here is one of many versions of using cURL that has not yielded the final URL after redirect:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
$header = curl_getinfo($ch);
var_dump($response);
var_dump($header);
I've also tried toggling the HEADER, FOLLOWLOCATION, RETURNTRANSFER, AUTOREFERER, and other options without progress.