CURL returns code 303

0

I have the following code:

$fields = array('usuario'=>urlencode($jm->Login),'senha'=>$jm->Senha);//url-ify the data for the POST
$fields_string = '';
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&'; }
$url = "https://www.sitecliente.com.br/validar/";
$ch = curl_init();//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);//execute post
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);//close connection
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "STATUS: ";
print_r($status);
curl_close($ch);

The goal is to click on a link within our system, to be directed to an external system. When we do this, it validates, but the page goes blank. When giving a print in status, it returns the message: STATUS: 303.

I noticed that this error can be because we are using POST and should use GET. How would I do that?

    
asked by anonymous 21.06.2016 / 22:41

1 answer

0

To send by GET method:

curl_setopt($ch, CURLOPT_POST, 0);

Alternatively you can use CURLOPT_CUSTOMREQUEST

curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'GET');

I remember responding to something about CURL a few months ago, so I did a search and to my surprise I found a question from you that I answered: How do I step parameters by curl?

This link elucidates the same questions you are posting here again, so I found it relevant to post.

Returning to the subject of the current question, note that this does not make sense:

curl_setopt($ch,CURLOPT_POST,count($fields));

The value is boolean true / false or 1/0 where 1 is true and 0 is false. Anyway, this is also explained in the link of the question asked in April.

One more remark, I am not guaranteeing that the status http 303 will resolve because the problem may have a different cause than the one commented on in the question.

    
21.06.2016 / 23:17