php Headerからクッキーを取得

577 ワード

/*-----  COOKIE-----*/
$url = 'www.xxx.com'; //url  
$post = "id=user&pwd=123456"; //POST  
$ch = curl_init($url); //   
curl_setopt($ch,CURLOPT_HEADER,1); //              
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //          
curl_setopt($ch,CURLOPT_POSTFIELDS,$post); //  POST  
$content = curl_exec($ch); //  curl    $content
preg_match('/Set-Cookie:(.*);/iU',$content,$str); //    
$cookie = $str[1]; //  COOKIE(SESSIONID)
curl_close($ch); //  curl
/*-----  COOKIE-----*/
curl_setopt($ch,CURLOPT_COOKIE,$cookie);