0
Colleagues.
I have a Curl which when running brings this value:
Login: Fernando Pessoa, password: x2cz
But I need to take this value and play inside another Url to be automatically logged in. I’m trying this way:
$output = curl_exec($curl); // resultado da curl anterior a essa
$obj = json_decode($output,true);
curk_init();
curl_setopt($curl, CURLOPT_URL, "https://site.com.br/");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($obj))
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $obj);
$resultado = curl_exec($curl);
echo $resultado;
The variable
$output
stores the valuelogin: Fernando Pessoa, senha: x2cz
? If yes, why are you using the functionjson_decode
in a string that is not a JSON? The intention would be to generate an associative array? Describe how the POST of the second Curl should be.– rodorgas
Actually the login value: Fernando Pessoa, password: x2cz comes from another URL I’m using, which takes the values of a json. But I need to take this value and access the other site already logged in.
– user24136
Would $output = curl_exec($Curl); from the previous Curl
– user24136
You need to clarify: 1) what the content of the $obj variable (check with var_dump) and 2) is like the POST you want to mount for the second request (I suppose it’s something like
login=Fernando Pessoa&senha=z2cz
).– rodorgas
Actually I don’t even think you need json. I gave a print_r and returned it (abbreviated to take only the data I need). {"name":"Fernando Pessoa","responsavel":[{"email":"[email protected]","message":"Successfully registered, password: bns7"}],
– user24136