Was willst Du den genau machen? Den ersten Cookie holen und analysieren?
function First_GetCookie()
{
//german
$url = "https://alexa.amazon.de";
//english
//$url = "https://alexa.amazon.com";
$sCookieFile = tempnam(sys_get_temp_dir(), 'Cookie_Alexa');
var_dump($sCookieFile);
// open a site with cookies
$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, "http://www.google.com");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0');
curl_setopt($ch, CURLOPT_HEADER ,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $sCookieFile); //could be empty, but cause problems on some hosts
curl_setopt($ch, CURLOPT_COOKIEFILE, $sCookieFile); //could be empty, but cause problems on some hosts
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$content = curl_exec($ch);
// get header
$headers=array();
$data=explode("
",$content);
//var_dump($data);
$headers['status']=$data[0];
//var_dump($headers);
array_shift($data);
//var_dump($data);
foreach($data as $key => $part)
{
$middle = strpos($part, ":");
//var_dump($middle);
if($middle)
{
$headertype = substr($part, 0, $middle);
//var_dump($headertype);
$headercontent = substr($part, $middle+2);
//var_dump($headercontent);
if(headertype($headertype))
{
$headers[$headertype] = $headercontent;
}
}
//$middle = explode (":",$part);
//var_dump($middle);
//$headers[trim($middle[0])] = trim($middle[1]);
}
//print all headers as array
echo "<pre>";
print_r($headers);
echo "</pre>";
// get location
$location = $headers["Location"];
var_dump($location);
SetValue(39195 /*[Geräte\Amazon Echo Alexa\Amazon Steuerung\Location First Login]*/, $location);
// get cookies
$cookies = array();
preg_match_all('/Set-Cookie:(?<cookie>\s{0,}.*)$/im', $content, $cookies);
print_r($cookies['cookie']); // show harvested cookies
// basic parsing of cookie strings (just an example)
$cookieParts = array();
preg_match_all('/Set-Cookie:\s{0,}(?P<name>[^=]*)=(?P<value>[^;]*).*?expires=(?P<expires>[^;]*).*?path=(?P<path>[^;]*).*?domain=(?P<domain>[^\s;]*).*?$/im', $content, $cookieParts);
//print_r($cookieParts);
$amzcookie = $cookies['cookie'];
//Session ID
$session_id_info = GetSessionID($amzcookie);
$session_id = $session_id_info['session_id'];
$session_id_time = $session_id_info['session_id_time'];
// var_dump($session_id);
// var_dump($session_id_time);
SetValue(56031 /*[Geräte\Amazon Echo Alexa\Amazon Steuerung\Neuer Cookie Ansatz\Session ID First Login]*/, $session_id);
SetValue(34145 /*[Geräte\Amazon Echo Alexa\Amazon Steuerung\Neuer Cookie Ansatz\Session ID Time]*/, $session_id_time);
// Hidden Field suchen
// var_dump($content);
return $sCookieFile;
}
function headertype($headertype)
{
$headertypes = array("x-amzn-RequestId", "Location", "Content-Length", "Date", "Server", "Content-Type", "Strict-Transport-Security", "x-ua-compatible", "Pragma", "Cache-Control", "Expires", "X-Frame-Options", "P3P", "Vary", "Date", "Transfer-Encoding", "Connection");
if(in_array($headertype, $headertypes))
{
$useheadertype = true;
}
else
{
$useheadertype = false;
}
return $useheadertype;
}
function GetSessionID($amzcookie)
{
$session_id_info = array();
foreach ($amzcookie as $cookie)
{
$pos_session_id_start = strpos($cookie, "session-id=");
//var_dump($pos_session_id_start);
if($pos_session_id_start)
{
$pos_session_id_end = strpos($cookie, ";");
//var_dump($pos_session_id_end);
$session_id = substr($cookie, $pos_session_id_start+11, $pos_session_id_end-12);
$session_id_info['session_id'] = $session_id;
}
$pos_session_id_time_start = strpos($cookie, "session-id-time=");
//var_dump($pos_session_id_start);
if($pos_session_id_time_start)
{
$pos_session_id_time_end = strpos($cookie, ";");
//var_dump($pos_session_id_end);
$session_id_time = substr($cookie, $pos_session_id_time_start+16, $pos_session_id_time_end-17);
$session_id_info['session_id_time'] = $session_id_time;
}
//var_dump($pos_session_id_start);
}
return $session_id_info;
}
$first_cookie = First_GetCookie();
var_dump($first_cookie);
Problem ist wohin den Cookie in der Struktur von IP-Symcon speichern bzw. auf welches Verzeichnis hat IPS sinnvollerweise Zugriffsrechte in die man z.B. ein Temp Cookie ablegen könnte. Andere Möglichkeit wäre den Cookie zerlegen und nur die Teile abspeichern die man braucht. Insbesondere die Hidden Fields brauchst Du und das macht mir persönlich Probleme.
Aber wenn sich da da eine sinnvolle Lösung findet wäre das gut dann könnte man einen Timer laufen lassen der die wichtigen Daten einfach im Hintergrund erneuert.