php - Transfer cookies & session from CURL to header location -


i have curl request sending data external source. after post completed, extract destination url , redirect through header("location: $url");.

problem: while redirect, data no longer present. cookie or session not being passed through header location.

what best way of transferring header details header location?

$ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_cookiesession, true); curl_setopt($ch, curlopt_header, true); curl_setopt($ch, curlopt_postfields, 'postdata=' . urlencode(xmldata())); curl_setopt($ch, curlopt_httpheader, array('content-type: application/x-www-form-urlencoded')); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_fresh_connect, 10); curl_setopt($ch, curlopt_cookiejar, 'cookie.txt'); curl_setopt($ch, curlopt_cookiefile, 'cookie.txt');  // download given url, , return output $output = curl_exec($ch);  // cookie match preg_match_all('/^set-cookie:\s*([^\r\n]*)/mi', $output, $ms); // print_r($result); $cookies = array(); foreach ($ms[1] $m) {     list($name, $value) = explode('=', $m, 2);     $cookies[$name] = $value; } print_r($cookies);  $redirect = curl_getinfo($ch)['redirect_url'];  header('http/1.1 307 temporary redirect'); header("location: $redirect");  //close match curl_close($ch); 

i tried cookie preg match brings empty array.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -