F
F
ff00ff2014-06-25 20:54:54
PHP
ff00ff, 2014-06-25 20:54:54

How can I get all server response codes when working with cURL?

I send a request to the server using php and cURL, but I can't intercept if there was a redirect with a 301 code to another page.
curl_getinfo($ch,CURLINFO_HTTP_CODE);
This code returns only the last received HTTP code.
When using this code, all headers are returned, but along with the web page.
curl_setopt($ch, CURLOPT_HEADER, 1);
Is it possible to somehow get this data separately without sending extra requests?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Entelis, 2014-06-25
@ff00ff

A redirect is just another request anyway.
You can write your own redirect handler
. To do this, we
look at the headers, if necessary, we request a new page (and so on in the loop until victory)

S
stas, 2014-06-26
@stas3572

curl_getinfo():
CURLINFO_REDIRECT_COUNT - number of redirects
CURLINFO_REDIRECT_TIME - time for redirects, in seconds
curl_setopt():
CURLOPT_VERBOSE - additional output. information
can help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question