\n/', $result, $matches);
$password = $matches[1];
# Nos piden que nos re-autentiquemos con los datos de usuario + la cookie y nos devuelven un token de sesion
curl_setopt($ch, CURLOPT_URL, "https://copiagenda.movistar.es/cp/ps/Main/login/Authenticate");
$postdata = "password=$password&u=$tm_login&d=movistar.es";
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_GET, false);
# cabeceras HTTP
$header = array("Content-Type: application/x-www-form-urlencoded",
"Content-Length: ".strlen($postdata),
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*",
"Cookie: skf=$cookie_value1; s=$cookie_value2",
"Connection: Keep-Alive");
$result = curl_exec ($ch);
$matches = array();
preg_match('/&t=(.*?)"\n/', $result, $matches);
$token = $matches[1];
# Pedimos un exportado de los datos en fichero txt separado por tabuladores
$urlfinal = "https://copiagenda.movistar.es/cp/ps/PSPab/preferences/ExportContacts?d=movistar.es&c=yes&u=$tm_login&t=$token";
curl_setopt($ch, CURLOPT_URL, $urlfinal);
$postdata = "fileFormat=TEXT&charset=8859_1&delimiter=TAB";
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_GET, false);
# cabeceras HTTP
$header = array("Content-Type: application/x-www-form-urlencoded",
"Content-Length: ".strlen($postdata),
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*",
"Cookie: skf=$cookie_value1; s=$cookie_value2",
"Connection: Keep-Alive");
# En este caso nos interesa eliminar las cabeceras
curl_setopt ($ch, CURLOPT_HEADER, false);
$result = curl_exec ($ch);
$lista_contactos = $result;
}
else
{
print "No redirigido";
}
curl_close($ch);
}
$agenda = ParseaRespuesta($lista_contactos);
return $agenda;
}
function BuscaPorNombre($nombre, $agenda)
{
$count = count($agenda);
for($i = 1; $i < $count; $i++)
{
$contacto = split("\t",$agenda[$i]);
$nombreag = trim($contacto[3]);
$longnombre = strlen($nombreag);
$contacto[3] = substr($nombreag,1,$longnombre-2);
$telefono = trim($contacto[11]);
$longnumero = strlen($telefono);
$contacto[11] = substr($telefono,1,$longnumero-2);
if(eregi($nombre,$contacto[3]))
return $contacto;
}
}
$log = "6xxxxxxxx";
$passw = "xxxxxx";
$lista = RecuperaContactos($log, $passw);
$busca = "nombre";
$contacto = BuscaPorNombre($busca, $lista);
if($contacto[3]=="")
print "Contacto '$busca' no encontrado
";
else
print $contacto[3]." ".$contacto[11]."
";
?>