...

View Full Version : CURL saving content to file



majmuncina
08-25-2011, 03:10 AM
<html>
<title>MyBB PM Exporter</title>
<body>
<form action ="<?php $_SERVER['PHP_SELF'] ?>" method="post">
URL to site: <input type ="text" name="site" value='community.mybb.com' /><br>
Full path to user:pwd list: <input type ="text" name="path" value='/home/www/list.txt' /><br>
<input type = "submit" value="Export" />
</form>
</body>
</html>

<?php


if(isset($_POST['path']) && isset($_POST['site']))
{
$list = $_POST['path'];
$url = $_POST['site'];

$file = file($list);
foreach($file as $line){
$explode = explode(":",$line);
$username = $explode[0];
$password = $explode[1];



$crl = curl_init();

curl_setopt($crl, CURLOPT_URL, $url."/member.php");
curl_setopt($crl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($crl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);


// This array will hold the field names and values.
$postdata=array(
"username"=>"$username",
"password"=>"$password",
"remember"=>"no",
"submit"=>"Login",
"action"=>"do_login",
"url"=>$url."/member.php"
);
// Tell curl we're going to send $postdata as the POST data
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);

$result=curl_exec($crl);
$find_key = preg_match('/var my_post_key = "(.*?)"/',$result,$match);
$my_post_key = $match[1];

curl_setopt($crl, CURLOPT_URL, $url."/private.php");
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);

// This array will hold the field names and values.
$postdata=array(
"my_post_key" => $my_post_key,
"exportfolders[]" => "all",
"dayway" => "disregard",
"exportunread" => "1",
"deletepms" => "0",
"exporttype" => "html",
"action" => "do_export",
"submit" => "Export Private Messages"
);
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);


$fh = fopen($username.".html", 'w');
curl_setopt($crl, CURLOPT_FILE, $fh);
curl_exec($crl);
fclose($fh);
curl_close($crl);


}


}
?>

So , basically this code just opens the file where username:password is located and then it logins to community.mybb.com with each combination in that file and saves the content of pm's of logged in user.
Problem is that this script allways saves pm's of only one user and it saves other usernames pm's but with the same content of the first user.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum