Kod
<?php
function token($content)
{
preg_match("@<input type=\"hidden\" id=\"_token\" name=\"_token\" value=\"(.*?)\" \/>@i", $content, $w);
return $w[1];
}
$hand = curl_init();
//pobieranie tokena
curl_setopt($hand, CURLOPT_URL, 'http://www.erepublik.com/en/login');
curl_setopt($hand, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($hand, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1)");
$p=curl_exec($hand);
$token = token($p);
//logowanie
curl_setopt($hand, CURLOPT_URL, 'http://www.erepublik.com/en/login');
curl_setopt($hand, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($hand, CURLOPT_POST, 1);
curl_setopt($hand, CURLOPT_POSTFIELDS, "_token={$token}&citizen_name=login&citizen_password=haslo&commit=Login");
curl_setopt($hand, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1)");
$p=curl_exec($hand);
echo htmlspecialchars($p);
curl_close($hand);
?>
function token($content)
{
preg_match("@<input type=\"hidden\" id=\"_token\" name=\"_token\" value=\"(.*?)\" \/>@i", $content, $w);
return $w[1];
}
$hand = curl_init();
//pobieranie tokena
curl_setopt($hand, CURLOPT_URL, 'http://www.erepublik.com/en/login');
curl_setopt($hand, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($hand, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1)");
$p=curl_exec($hand);
$token = token($p);
//logowanie
curl_setopt($hand, CURLOPT_URL, 'http://www.erepublik.com/en/login');
curl_setopt($hand, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($hand, CURLOPT_POST, 1);
curl_setopt($hand, CURLOPT_POSTFIELDS, "_token={$token}&citizen_name=login&citizen_password=haslo&commit=Login");
curl_setopt($hand, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1)");
$p=curl_exec($hand);
echo htmlspecialchars($p);
curl_close($hand);
?>