I have the following code which logs me into my NAS's audio player:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, webapi.auth.'?api=SYNO.API.Auth&method=Login&version=3&account=[user]&passwd=[pass]');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$content = curl_exec($ch);
// get cookies
$cookies = array();
preg_match_all('/Set-Cookie:(?<cookie>\s{0,}.*)$/im', $content, $cookies);
?>
Now how can I reuse the cookies string in a follow up action?
<?php
$ch = curl_init(webapi.remoteplayer);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
$content = curl_exec($ch); curl_close($ch);
?>