D@nil
Постоялец
- Регистрация
- 1 Окт 2006
- Сообщения
- 340
- Реакции
- 122
- Автор темы
- #1
Здравствуйте, подскажите как можно переписать код с использованием сокетов
На использование curl
Я начал, но не могу залогиниться.
подскажите в чем проблема
PHP:
function li_post($login, $password, $n_title, $n_body) {
//переменные с куки
$bbuserid = - 1;
$bbpassword = - 1;
$bbusername = $login;
$bbredirect = $login;
$jurl = - 1;
//пакет авторизации
$pst_data = "action=login&charset=utf&username=" . $login . "&password=" . $password;
$headr = "POST /member.php HTTP/1.1\r\n";
$headr .= "Host: www.liveinternet.ru\r\n";
$headr .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3\r\n";
$headr .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$headr .= "Accept-Language: ru,en-us;q=0.7,en;q=0.3\r\n";
$headr .= "Connection: keep-alive\r\n";
$headr .= "Referer: http://www.liveinternet.ru/\r\n";
$headr .= "Content-Type: application/x-www-form-urlencoded\r\n";
$headr .= "Content-Length: " . strlen ( $pst_data ) . "\r\n\r\n";
$headr .= $pst_data;
$sct = fsockopen ( "www.liveinternet.ru", 80 );
fputs ( $sct, $headr );
while ( ! feof ( $sct ) ) {
$sanswer = fgets ( $sct, 4096 );
if ($st = strstr ( $sanswer, "set-cookie: bbuserid=" )) {
$eps = strpos ( $st, ";" );
$bbuserid = substr ( $st, 21, $eps - 21 );
}
if ($st = strstr ( $sanswer, "set-cookie: bbpassword=" )) {
$eps = strpos ( $st, ";" );
$bbpassword = substr ( $st, 23, $eps - 23 );
}
if ($st = strstr ( $sanswer, "set-cookie: jurl=" )) {
$eps = strpos ( $st, ";" );
$jurl = substr ( $st, 17, $eps - 17 );
}
}
fclose ( $sct );
//пакет постинга новости
$form_data = "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"action\"\r\n";
$form_data .= "\r\n";
$form_data .= "newpost\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"parsing\"\r\n";
$form_data .= "\r\n";
$form_data .= "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"journalid\"\r\n";
$form_data .= "\r\n";
$form_data .= $bbuserid . "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"backurl\"\r\n";
$form_data .= "\r\n";
$form_data .= "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"selectforum\"\r\n";
$form_data .= "\r\n";
$form_data .= "/journal_post.php?journalid=" . $bbuserid . "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"action\"\r\n";
$form_data .= "\r\n";
$form_data .= "n_add\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"nurl\"\r\n";
$form_data .= "\r\n";
$form_data .= "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"headerofpost\"\r\n";
$form_data .= "\r\n";
$form_data .= $n_title . "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"mode\"\r\n";
$form_data .= "\r\n";
$form_data .= "0\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"status\"\r\n";
$form_data .= "\r\n";
$form_data .= "Use these controls to insert vBcode\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"message\"\r\n";
$form_data .= "\r\n";
$form_data .= $n_body . "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"tags\"\r\n";
$form_data .= "\r\n";
$form_data .= "\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"make_br_sel\"\r\n";
$form_data .= "\r\n";
$form_data .= "yes\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"commentsubscribe\"\r\n";
$form_data .= "\r\n";
$form_data .= "yes\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"nocomment\"\r\n";
$form_data .= "\r\n";
$form_data .= "0\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"parseurl\"\r\n";
$form_data .= "\r\n";
$form_data .= "yes\r\n";
$form_data .= "-----------------------------41184676334\r\n";
$form_data .= "Content-Disposition: form-data; name=\"close_level\"\r\n";
$form_data .= "\r\n";
$form_data .= "0\r\n";
$form_data .= "-----------------------------41184676334--\r\n";
$headr = "POST /journal_addpost.php HTTP/1.1\r\n";
$headr .= "Host: www.liveinternet.ru\r\n";
$headr .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3\r\n";
$headr .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$headr .= "Accept-Language: ru,en-us;q=0.7,en;q=0.3\r\n";
$headr .= "Connection: keep-alive\r\n";
$headr .= "Referer: http://www.liveinternet.ru/journal_post.php?journalid=" . $bbuserid . "&action=n_add\r\n";
$headr .= "Cookie: bbuserid=" . $bbuserid . "; bbpassword=" . $bbpassword . "; bbusername=" . $bbusername . "; jurl=" . $jurl . "; chbx=guest\r\n";
$headr .= "Content-Type: multipart/form-data; boundary=---------------------------41184676334\r\n";
$headr .= "Content-Length: " . strlen ( $form_data ) . "\r\n\r\n";
$headr .= $form_data;
$sct = fsockopen ( "www.liveinternet.ru", 80 );
fputs ( $sct, $headr );
while ( ! feof ( $sct ) ) {
$sanswer = fgets ( $sct, 4096 );
}
print ( "Done!" );
}
Я начал, но не могу залогиниться.
PHP:
$post="action=login&charset=utf&username=___&password=___";
echo post ( 'http://www.liveinternet.ru/member.php',$post,'http://www.liveinternet.ru/' ));
function post($url = '', $content = '', $referer = '') {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
//curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 15 );
curl_setopt ( $ch, CURLOPT_COOKIEFILE, "cookiefile" );
curl_setopt ( $ch, CURLOPT_COOKIEJAR, "cookiefile" );
curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208' );
if (! empty ( $content )) {
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $content );
} else {
curl_setopt ( $ch, CURLOPT_POST, 0 );
}
if (! empty ( $referer ))
curl_setopt ( $ch, CURLOPT_REFERER, $referer );
$ss = curl_exec ( $ch );
curl_close ( $ch );
return $ss;
}
подскажите в чем проблема