I did a search on the site before asking this question, but I believe this hasn’t been asked before; apologies if it already has been and I missed on finding it.
What I’m trying to achieve is a little ‘weird’, I guess?
So, say for example, I’m POST’ing (or GET’ing from) data to a page that returns the response along with a ‘Location’ in the header that I want it to follow. Under most circumstances, this would be no problem as I could just grab the ‘Location’ value from the headers, then follow it.
However, consider this scenario:
The website/page I’m getting data from is sending me a Location header, and the resulting redirect has yet another ‘Location’ header. This is random, some redirects will give me the expected file after 2 redirects, others after 4, or so.
I absolutely need to record the most recent (last) ‘Location’ value that was sent to me. How do I do that? I currently have PHP Curl’s Follow Location set to ‘on’ so it automatically follows any/all locations without me intervening. Since it does this, how do I grab the value of the last location it followed?
Example, I post data to Website A using php curl. The reply from Website A contains a ‘Location’ redirect to Website B. PHP Curl follows it. Website B has a ‘Location’ redirect, yet again, to Website C. PHP Curl automatically follows it. Website C then has a ‘Location’ redirect to Website D. PHP Curl automatically follows it, as it did before. Website D, then, sends me the actual file I wanted to download.
Since PHP Curl is automatically following the ‘Location’, how do I grab the last Location value? In the example above, how would I grab the ‘Location’ value in Website C, which was the last one followed before reaching Website D, the end destination?
Apologies if I haven’t been clear enough, I’ve tried my best to explain what I want to do; it’s just the situation is a bit tricky to put into words.
Do you look for something like this?
you can find the documentation on
curl_getinfo()here http://www.php.net/manual/en/function.curl-getinfo.phpAs I read your question a second time my answer is probably not the final solution, but you could get the HTTP Header information from the last location and grab the
HTTP_REFERER. I don’t have an example for this but this could be a way you will get the information you need.