I have read and try all possible uses of php cURL but with no luck.
Is possible to login from my-site.com using cURL to remote-site.com and next open remote-site.com and browse it as logged user?
Web browser does not seems to save session cookies after cURL request.
last try:
$cfile = tempnam ('C:/tmp', 'NCOOKIE');
$data = array (
'username' => 'username',
'password' => 'password'
);
$c = curl_init();
curl_setopt($c, CURLOPT_HEADER, true);
curl_setopt($c, CURLOPT_NOBODY, false);
curl_setopt($c, CURLOPT_URL, 'http://remote-site.com/login.php');
curl_setopt($c, CURLOPT_COOKIESESSION, true);
curl_setopt($c, CURLOPT_COOKIEJAR, $cfile);
curl_setopt($c, CURLOPT_COOKIEFILE, $cfile);
curl_setopt($c, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query($data));
session_write_close();
$g = curl_exec($c);
session_start();
$hs = curl_getinfo($c, CURLINFO_HEADER_SIZE); // header size
$h = substr($g, 0, $hs); // header
$g = substr($g, $hs); // body
curl_close($c);