joe
joe

Reputation: 1135

CURLOPT_FOLLOWLOCATION

I looked up google for more information. But the more I read, the more I am confused or wonder

I understand that CURLOPT_FOLLOWLOCATION() follows "the location", but what is the location? Is it the url that is initialized?

  curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, false); 

I only need to post data into icontact mailing list - so would this snippet above prevent the data from going in the mailing list?

I printed $result and see that the data went in the correct mailing list although I cannot see whether the data are the correct ones which are from form.

Upvotes: 12

Views: 40441

Answers (3)

Akash Sharma
Akash Sharma

Reputation: 11

If you set CURLOPT_FOLLOWLOCATION to true (or 1), cURL will automatically follow these redirects. This means that if the server responds with a 3xx status code (e.g., 302 Found, 301 Moved Permanently, etc.), cURL will make a new request to the URL specified in the Location header of the response.

If you set CURLOPT_FOLLOWLOCATION to false (or 0), cURL will not follow redirects. In this case, you'll receive the response for the redirect response (3xx status) rather than the final destination.

Upvotes: 0

Álvaro González
Álvaro González

Reputation: 146540

Quoting from docs:

CURLOPT_FOLLOWLOCATION TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).

When you request a URL, you can sometimes be redirected to some other URL. In PHP it'd be done with:

header('Location: http://example.com/');

This directive instructs CURL to load that URL instead of the original one, as HTTP mandates. There's normally no good reason to disable it.

Upvotes: 19

Not_a_Golfer
Not_a_Golfer

Reputation: 49255

It tells CURL to ignore 30x HTTP redirect headers or not. If set to true, "Location: <someurl>" HTTP headers in the response will cause CURL to issue another request to the location specified in this header.

Upvotes: 5

Related Questions