Reputation: 11494
I've seen curl_setopt($ch, CURLOPT_POST, 1);
mostly written in this way but have noticed that some people express the count()
number of post fields instead of 1
/true
. Why might they be doing this or could it simply be a misunderstanding of the option?
Upvotes: 0
Views: 312
Reputation: 21694
From the documentation:
A parameter set to 1 tells libcurl to do a regular HTTP post. This will also make the library use a "Content-Type: application/x-www-form-urlencoded" header. (This is by far the most commonly used POST method).
Seems to me like it's a boolean. The content-type is enforced for POST requests to be sent properly, which are already default that way in HTML forms that use POST, but not in cURL requests - they have to be set up for it (so this flag is the equivalent of method="post"
or method="get"
depending on which value you give it, >=1
or 0
respectively.
The reason you saw count($data)
in this field in some places is to (in my assumption) disable POST
when the $data
is empty dynamically, so it's 0
when it is empty and >=1
otherwise.
Upvotes: 1