curl 経由でログインし、今後の呼び出しのために Cookie とセッション情報を維持したいと考えています。同じディレクトリに Cookie テキスト ファイルを作成し、 CURLOPT_COOKIEJAR 、 CURLOPT_COOKIEFILE を使用して CUL で Cookie を維持します。ログインAPIを呼び出そうとすると、古いCookieが取得され、以前のユーザー情報が表示されます。さまざまなユーザー Cookie を維持し、通常のブラウザー ハンドルのようにセッションを維持する必要があります。どうやってするか。誰もがそれを行うためのアイデアを提供します.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER,0); // TRUE to include the header in the output.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // it will follow with server redirects
curl_setopt($ch,CURLOPT_AUTOREFERER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//ssl certificate verifyer
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //ssl certificate host
// Set the location of and send the cookies
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookies.txt");
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
$result = curl_exec($ch); //execute curl and store data in result