If I execute a cURL request that is set to follow redirects and return the headers, it returns the headers for ALL of the redirects.
I only want the last header returned (and the content body). How do I achieve that?
If I execute a cURL request that is set to follow redirects and return the headers, it returns the headers for ALL of the redirects.
I only want the last header returned (and the content body). How do I achieve that?
Search the output for "HTTP/1.1 200 OK" in the beginning of the line - this is where your last request will begin. All others will give other HTTP return codes.
Here's another way:
Of course, you'll need more error checking, such as for timeout, etc.
Execute your request
Take the length of the header from
curl_getinfo
s return valueRetrieve the part between the last
\r\n\r\n
(but before the end of the header) and the end of the header as last headerOf course if you have PHP < 5.3 you have to expand the elvis operator to an if/else construct.
Late answer, but maybe more simple way to;