나는 cUrl (PHP)을 사용하여 로그인 요청을 게시하고 응답을 쿠키 파일에 저장합니다. 두 번째 요청에서 헤더에 쿠키를 전달하고 확인을 위해 데이터를 게시합니다.curl 쿠키가 성공시 생성되지 않음
첫 번째 요청에서 쿠키 파일이 생성되지 않아 두 번째 요청이 실패하는 문제가 있습니다. 내가 잘못하고있는 곳에 나에게 제안 해주세요.
$cookiefile="/var/www/html/dimdim/cook.txt";
$url_log="http://my.dimdim.com/api/auth/login";
$p_log='request={"account":"bin6k","password":"password","group":"all"}';
$url_ver="http://my.dimdim.com/api/auth/verify";
$p_ver='request={"account":"bin6k","password":"password","group":"all"}';
$ch = curl_init();
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_URL,$url_log);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p_log);
ob_start(); // prevent any output
$retval=curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
//print_r($retval);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_URL,$url_ver);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p_log);
$buf2 = curl_exec ($ch);
curl_close ($ch);
echo "<PRE>".htmlentities($buf2);