taky

i can usually figure stuff out if i just give myself enough time and play with my god, but ive been doing alot of experimenting in curl_multi and for the life of my i really cant figure this one out. heres the deal. this script is meant to login to a specific site with 50 usernames and post on loops until the value $u is compensated for. it works, but heres the thing: i have to run the script twice. once to create the cookies and fail a bunch of times, and a second time to actually get some post forms really working.

im not sure if its some kind of logic error thats really hard to track down for me or not, but if someone could offer me some insight it would be greatly appreciated  Applause


<?

php

 
$m = curl_multi_init(); $ch=array();

foreach ($accts as $i => $login){
$ch[$i]=curl_init();
$cookies = "misc/cookie$i.txt";
$cookies = str_replace('\','/', getcwd().'/'.$cookies);
curl_setopt($ch[$i],CURLOPT_COOKIEFILE,$cookies);
curl_setopt($ch[$i],CURLOPT_COOKIEJAR,$cookies);
curl_setopt($ch[$i],CURLOPT_COOKIESESSION,1);
curl_setopt($ch[$i],CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)");
curl_setopt($ch[$i],CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch[$i],CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch[$i],CURLOPT_URL,"http://site.com/login.

php

 ");
curl_setopt($ch[$i],CURLOPT_POST,1);
$packet="username=".$login."&password=pass123&x=0&y=0&submit=Login";
curl_setopt($ch[$i],CURLOPT_POSTFIELDS,$packet);
curl_multi_add_handle($m,$ch[$i]);
}

//login
do { curl_multi_exec($m, $working); } while ($working);
curl_multi_close($m);

//i tried renaming the curl multi handler here thinking maybe it was the problem, ayeee nope
//i also tried using a different array for the curl resource expressions

$newm = curl_multi_init(); $new=array();

//logged in..
$u=3000; while ($u<500000){
foreach ($accts as $i => $login){
$u=$u+1;
$new[$i]=curl_init();
$cookies = "misc/cookie$i.txt";
$cookies = str_replace('\','/', getcwd().'/'.$cookies);

curl_setopt($new[$i],CURLOPT_COOKIEFILE,$cookies);
curl_setopt($new[$i],CURLOPT_COOKIEJAR,$cookies);
curl_setopt($new[$i],CURLOPT_COOKIESESSION,0);
curl_setopt($new[$i],CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)");
curl_setopt($new[$i],CURLOPT_FOLLOWLOCATION,1);
curl_setopt($new[$i],CURLOPT_RETURNTRANSFER,1);
curl_setopt($new[$i],CURLOPT_URL,"http://www.site.com/?u=".$u);
curl_setopt($new[$i],CURLOPT_POST,1);
$packet="comment=%5Burl%3Dhttp%3A%2F%2Fsitecom%5D%5Bimg%5Dhttp%3A%2F%2Fsite.com%2Fjpg.jpg%5B%2Fimg%5D%5B%2Furl%5D&submit=Submit";
curl_setopt($new[$i],CURLOPT_POSTFIELDS,$packet);
curl_multi_add_handle($newm,$new[$i]);
}

do { curl_multi_exec($newm, $working); } while ($working);

foreach ($accts as $i => $login){
$ok = curl_multi_getcontent($new[$i]);
if (strstr($ok,"Added comment successfully"Applause){
echo "Message sent!<br>";
}else{
echo "Message failed!<br>";
}
}
}
curl_multi_close($newm);

?>

vsloathe

Close your sockets one at a time. I'm not sure what you're trying to do with $u there, so I'm not sure how to help you.

emonk

Have you tried making sure that you don't have old cookies lying around, and that the cookie exists before using curl with it? I always do something like this in my 'fetch' functions before running curl, because old cookies bite me in the ass alot.

    if ( isset($cookiePath) ) {
        if(!file_exists($cookiePath)) {
        $fh = fopen($cookiePath, 'w+');
        fclose($fh);
        }


Just a thought.


Perkiset's Place Home   Politics @ Perkiset's