Dawid
Baruch
PHP & IP.Board
Developer
Temat: curl i logowanie na onet.pl
Witajcie,mam mały problem z zalogowaniem się na onet, przy użyciu curla. Mam taki kod:
$form_action = "https://konto.onet.pl/login.html?app_id=203";
$post_elements = array(
'login' => $this->login,
'password' => $this->password,
'perm' => 0,
'cookie' => 'onet_ubi, onetzuo_ticket, onet_cid, __utma, __utmz, onet_aui, onet_uoi, __gads, onet_crt_adtech, __utma, __utmz, __utmc, onet_sid',
'script' => rand( 2000, 3000 ),
);
$file_path = sys_get_temp_dir() . time(). "{$this->memberData[ 'member_id' ]}onet.cookie";
$curl = curl_init();
curl_setopt( $curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1" );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, false );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_COOKIEFILE, $file_path );
curl_setopt( $curl, CURLOPT_COOKIEJAR, $file_path );
if( strtoupper( substr( PHP_OS, 0,3 ) ) == 'WIN' )
{
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 30/2 );
}
else
{
curl_setopt( $curl, CURLOPT_TIMEOUT, 30 );
}
curl_setopt( $curl, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $curl, CURLOPT_URL, 'http://kontakty.onet.pl/' );
curl_setopt( $curl, CURLOPT_REFERER, '' );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_HEADER, 1 );
curl_setopt( $curl, CURLOPT_POST, false );
curl_setopt( $curl, CURLOPT_HTTPGET, true );
$result = curl_exec( $curl );
$sesid = $this->getElementString( $result, 'onet_sid=', ";" );
curl_setopt( $curl, CURLOPT_COOKIE, "onet_sid={$sesid}");
$naglowki = array(
'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'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',
'Content-Type: application/x-www-form-urlencoded'
);
curl_setopt( $curl, CURLOPT_URL, $form_action );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $naglowki );
curl_setopt( $curl, CURLOPT_ENCODING, 'gzip' );
curl_setopt( $curl, CURLOPT_ENCODING, 'deflate' );
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_COOKIESESSION, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $post_elements, '', '&' ) );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $curl, CURLOPT_HEADER, 1 );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_REFERER, $form_action );
curl_setopt( $curl, CURLOPT_HTTPGET, false );
$result = curl_exec( $curl );
echo '<pre style="text-align: left;">';
var_dump($result);
echo '</pre>';exit;
ale niestety cały czas $result zwraca mi stronę logowania. Macie jakiś pomysł co może być nie tak?