The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 06:46:07 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: curl_multi for gods sake.  (Read 2052 times)
taky
Rookie
**
Offline Offline

Posts: 13


View Profile
« on: January 09, 2008, 09:21:15 AM »

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  Praise

Code:
<?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")){
echo "Message sent!<br>";
}else{
echo "Message failed!<br>";
}
}
}
curl_multi_close($newm);

?>

« Last Edit: January 09, 2008, 09:23:20 AM by taky » Logged

No links in signatures please
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: January 09, 2008, 11:43:09 AM »

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.
Logged

hai
emonk
Rookie
**
Offline Offline

Posts: 44


View Profile
« Reply #2 on: January 09, 2008, 11:59:45 AM »

 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.

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

 Just a thought.
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!