$path_cookie = 'connexion_temporaire.txt';
if ( !file_exists($path_cookie) ) touch ( $path_cookie );
$curl = curl_init();
$postfields = array(
'action' => 'edit',
'format'=> 'json',
'token' => '+\\',
'title' => '111',
'text' => 'article',
'basetimestamp' => time()
);
curl_setopt($curl, CURLOPT_URL, 'http://wiki.info/api.php' );
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIEJAR, $path_cookie); // you put your cookie in the file
$connexion = curl_exec ( $curl );
$json_connexion = json_decode ( $connexion, true );
preg_match ( '~\d{9}~is', $connexion, $CaptchaId );
// /!\ don't close the curl conection or initialize a new one or your session id will change !
$postfields = array(
'action' => 'edit',
'format'=> 'json',
'token' => '+\\',
'title' => '111',
'text' => 'article',
'basetimestamp' => time(),
'captchaword' => '31',
'captchaid' => $CaptchaId[0]
);
curl_setopt($curl, CURLOPT_URL, 'http://wiki.info/api.php' );
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIEFILE, $path_cookie); //get the previous cookie
$connexionToken=curl_exec($curl);