We have this code which calls to an API function, we would like to log all requests to a file (in a secure way). We can handle multiple requests at once. Code works smooth on production environment, we need to log calls to a file to verify which call made which error.
$userId = $current_user->ID;
$idRichiesta = $[login to view URL](100000,999999);
$timestamp = round(microtime(true) * 1000);
$terminalid = get_user_meta($userId,'billing_wcj_checkout_field_3');
$codPv = get_user_meta($userId,'billing_wcj_checkout_field_2');
$url = $domain;
$piva = get_user_meta($userId,'billing_wcj_checkout_field_1');
$servizio = 'EC';
$request = array('grant_type' => 'client_credentials','client_id' => '**','client_secret' => '**');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "**");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request));
curl_setopt($ch, CURLOPT_SSLCERT, $_SERVER['DOCUMENT_ROOT'].'/../../csr/**');
$response = curl_exec($ch);
$responseObj = json_decode($response);
$accessToken = $responseObj->access_token;
$request = array('timestamp'=>$timestamp,'idRichiesta'=>$idRichiesta[0],'terminalid'=>$terminalid[0],'codPv'=>$codPv[0],'url'=>$url,'piva'=>$piva[0],'servizio'=>$servizio);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "**");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$authorization = "Authorization: Bearer ".$accessToken;
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorization,'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
curl_setopt($ch, CURLOPT_SSLCERT, $_SERVER['DOCUMENT_ROOT'].'/../../csr/**');
$response = curl_exec($ch);
$responseObj = json_decode($response);
if($responseObj->esito=='OK')
{
$blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, get_current_network_id() );
if ( is_wp_error( $blog_id ) ) {
return false;
}
confirm_another_blog_signup( $domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta, $blog_id );
$blogUrl = get_blog_option($blog_id,'siteurl');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $blogUrl.'/wp-admin/[login to view URL]');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('action'=>'latepoint_activate'));
curl_exec($ch);
$tablePrifix = $wpdb->get_blog_prefix($blog_id);
$wpdb->insert($tablePrifix.'latepoint_settings', array("**')));
$wpdb->insert($tablePrifix.'latepoint_settings', array("name"=>"**')));
$wpdb->insert($tablePrifix.'latepoint_settings', array("name"=>"**')));
$wpdb->insert($tablePrifix.'latepoint_settings', array("name"=>"**')));
$wpdb->insert($tablePrifix.'latepoint_settings', array("name"=>"**')));
return true;
}
else
{
$errorMsg["1"] = "ERROR 1";
$errorMsg["2"] = "ERROR 2";
$errorMsg["3"] = "ERROR 3";
$errorMsg["4"] = "ERROR 4";
$errorMsg["99"] = "ERROR 99";
$errors->add('error',$errorMsg[abs($responseObj->codiceEsito)]);
signup_another_blog( $blogname, $blog_title, $errors );
return false;
}