Jump to content
Rila_xp

Cum se poate face un autoposter in php?

Recommended Posts

Posted (edited)

Am si eu o intrebare...vreau sa fac un autoposter in php dar nu stiu cum sa ma loghez cu cURL si sa pastrez acele cookieuri si apoi sa postez...pe un forum...sa zicem ca exemplu pe platforma pe care este si RST adica vbulletin!

Am incercat ceva dar vreau si de la voi o idee!

Eu am incercat ceva de genul asta si nu a mers


<?php
// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://rstcenter.com/forum/login.php?do=login');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'vb_login_username=user&vb_login_password=&s=&securitytoken=guest&do=login&vb_login_md5password=parolaencriptata&vb_login_md5password_utf=parolaencriptata');

// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);

// SET FILE TO DOWNLOAD
curl_setopt($ch, CURLOPT_URL, 'http://rstcenter.com/forum/newthread.php?do=newthread&f=24');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'subject=subiect%3F&message=mesaj&wysiwyg=0&taglist=&sendtrackbacks=&iconid=0&s=&securitytoken=1320514284-975614823fd0a1201d3b0cfa05a061a02907d674&f=24&do=postthread&posthash=&poststarttime=&loggedinuser=28951&sbutton=Submit+New+Thread&parseurl=1&vbseo_retrtitle=1&vbseo_is_retrtitle=1&emailupdate=9999&polloptions=4');


// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
$content = curl_exec ($ch);

// CLOSE CURL
curl_close ($ch);

?>

Edited by Rila_xp
Posted
..... dar nu stiu cum sa ma loghez cu cURL si sa pastrez acele cookieuri si apoi sa postez..

Salut,

Ceva de genul:


<?php

// ............. restul de cod ....
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 45);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// autentificare
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, "https://www.gigel.ro/login.php");
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=$user&password=$password");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_exec($ch);


// URL si POSTFIELDS sunt ca exemplu
// Liniile cu SSL sunt utile daca URL-ul este pe https

// ........... restul de cod ......

?>

Cred ca este necesar si chmod 777 pe cookie.txt, depinde sub ce user rulezi scriptul si daca are permisiune de scriere pe fisier.

Posted

Security token-ul trebuie sa il citesti din sursa paginii (o parsezi) dupa logare si sa il folosesti de acolo, nu cel fix, setat de tine. Se schimba la fiecare logare acel token.

Posted

mozilla + live http headers.

Vezi ce headere sunt trimise la post.

Daca ai ceva dinamic, il iei prin explode dupa ce faci request la pagina ( inainte de post ).

Foloseste functia asta pt. curl si post:

function curl($url, $cookie='', $post='') {
$rand = rand(100000,400000);
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/".$rand." Netscape/7.1 (ax)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if($post !== '') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if($cookie !== '') {
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec ($ch);
curl_close ($ch);
if($result == "") { curl($url, $cookie, $post); } else { return $result; }
}

trebuie sa setezi $cookie, incearca sa le dai nume unic sa nu se intercaleze.

$cookie = "cookies/random_".rand(100000,400000);

funcia o apelezi in felul urmator:

$login = curl("http://link.com", $cookie, $post);

ca sa te loghezi

$moloz = curl("http://link.com/pagina", $cookie);

ca sa navighezi pe pagini logat.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...