$ch = curl_init('https://example.com/api/method/login');
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, array('usr'=>'me@example.com','pwd'=>'password'));
curl_setopt($ch,CURLOPT_CUSTOMREQUEST, 'POST');
// common description bellow
curl_setopt($ch,CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch,CURLOPT_COOKIEJAR, '(your cookie file)');
curl_setopt($ch,CURLOPT_COOKIEFILE, '(your cookie file)');
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch,CURLOPT_TIMEOUT, (set secounds for timeout));
$response = curl_exec($ch);
$header = curl_getinfo($ch);
// 200? 404? or something?
$error_no = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
if($error_no!=200){
  // do something for login error
  // return or exit
}
$body = json_decode($response);
if(JSON_ERROR_NONE == json_last_error()){
  // $response is not valid (as JSON)
  // do something for login error
  // return or exit
}
// use $body

results matching ""

    No results matching ""