Codice PHP:
<?php
session_start();
header('Content-Type: text/plain; charset=ISO-8859-1');
error_reporting(E_ALL);
$ch = curl_init('http://it.altervista.org/cp_gateway.php');
curl_setopt($ch, CURLOPT_COOKIE, 'av_sid=' . session_id());
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'Azione=login&nick=urlstatus&password=****&login=Accedi');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'av.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'av.txt');
curl_setopt($ch, CURLOPT_HEADER, true);
$code = curl_exec($ch);
curl_close($ch);
echo '// cp_gateway.php headers', PHP_EOL, reset(explode("\r\n\r\n", $code, 2));
preg_match('/<form name="av_login" method="post" action="([^"]+?)">/i', $code, $h); // server
preg_match_all('/<input type="hidden" name="(nick|pass|group)" value="([^"]*?)">/i', $code, $m);
$nick = $m[2][0]; // nick
$pass = $m[2][1]; // password cifrata
$group = $m[2][2];
$cp = curl_init($h[1]);
curl_setopt($cp, CURLOPT_POST, true);
curl_setopt($cp, CURLOPT_POSTFIELDS, 'nick=' .$nick . '&pass=' . $pass . '&group=' . $group);
curl_setopt($cp, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cp, CURLOPT_COOKIEFILE, 'av.txt');
curl_setopt($cp, CURLOPT_COOKIEJAR, 'av.txt');
curl_setopt($cp, CURLOPT_HEADER, true);
$code = curl_exec($cp);
curl_close($cp);
echo PHP_EOL, '// ', $h[1], ' headers', PHP_EOL, reset(explode("\r\n\r\n", $code, 2));
?>
E vi faccio vedere l'output: