Kolega zapomina o tym, że PW do poprawnego zalogowania jak i innych akcji potrzebuje walidatora hslk. Na podstawie którego sprawdza oryginalność przesłanych danych(czy dane pochodzą z serwera).
hslk - Generowany jest przez serwis.
Więc najpierw musisz go pobrać do siebie.
A następnie stworzyć formularz i wysłać go przez CURL.
Dam Ci gotowca z moimi funkcjami. Aczkolwiek nie jestem pewny czy kod który Ci podam jest działający bo działający mam u siebie na PC, a jestem u swojej lubej.
<?php
/**
* Curl - Zalogowanie się do PW.
* Autor - Rafik89
*/
$login = "$$$$$$";
$password = "$$$$$";
$url_login = "http://prisonwars.gry.epuls.pl/";
$referer = "http://prisonwars.gry.epuls.pl/";
$url = "http://sanquentin.prisonwars.gry.epuls.pl/";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4";
$post = "hslk="._hslk(_cURL($url_login))."&log_in=1&login=".$login."&password=".$password;
$headers = array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: pl,en-us;q=0.7,en;q=0.3',
'Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7'
);
function _cURL($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$site = curl_exec($curl);
curl_close($curl);
return $site;
}
function _cURL_login($url, $post, $referer='', $agent='', $headers=''){
$curl=curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
if (isset($referer)){
curl_setopt($curl, CURLOPT_REFERER, $referer);
}
if (isset($agent)){
curl_setopt($curl, CURLOPT_USERAGENT, $agent);
}
if (isset($headers)){
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookies.txt');
curl_setopt($curl, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookies.txt');
curl_setopt($curl, CURLOPT_ENCODING, '');
$site = curl_exec($curl);
curl_close($curl);
return $site;
}
function _hslk($site){
if (preg_match("/hslk\' value=\'[a-z 0-9]+/i", $site, $val)){
$hslk = str_replace('hslk\' value=\'', '', $val['0']);
}
if (isset($hslk)){
return $hslk;
} else {
return false;
}
}
if ($dane = _cURL_login($url_login, $post, $referer, $agent, $headers)){
echo $dane;
}
?>