Jump to content

Curl remote Login script


djtozz

Recommended Posts

Hello,

 

I have a working script which can upload a file to megaupload using curl.

Now I would like to do a remote login,  before the script uploads the file

(This way the file is stored under my account , and not uploaded as guest)

 

So basicly I have 2 working peaces of code (the login and the file upload) and I just want to integrate them into one code, I simply don't know where to paste the login code.

 

 

Working Login Script:

$query = "login=1&redir=1&username=MY_USERNAME&password=MY_PASSWORD";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.megaupload.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

 

Working Upload script:

   $done = 0;

    $flag = 0;

    $file_loc = 'uploads/' . $info['name'];

    $url = 'http://megaupload.com';

    $file = @file ($url);

    $count = count ($file);

    $i = '0';

    while ($i < $count)

    {

      if (strstr ($file[$i], 'megaupload.com/upload_done.php'))

      {

        $main = $file[$i];

        $flag = 1;

        break;

      }



      ++$i;

    }



    if ($flag == 1)

    {

      $parse = explode ('action="', $main);

      $parse1 = explode ('" ', $parse[1]);

      $posturl = $parse1[0];

      $parse2 = explode ('UPLOAD_IDENTIFIER=', $posturl);

      $mega_uid = $parse2[1];

      $postcontent = array ();

      $postcontent['file'] = '@' . $file_loc;

      $postcontent['UPLOAD_IDENTIFIER'] = $mega_uid;

      $postcontent['sessionid'] = $mega_uid;

      $postcontent['message'] = '';

      $ch = curl_init ();

      curl_setopt ($ch, CURLOPT_URL, $posturl);

      curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);

      curl_setopt ($ch, CURLOPT_POST, 1);

      curl_setopt ($ch, CURLOPT_POSTFIELDS, $postcontent);

      curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

      $result = curl_exec ($ch);

      curl_close ($ch);

      $flag = 0;

      $file = explode ('
', $result);

      $count = count ($file);

      $i = '0';

      while ($i < $count)

      {

        if ((strstr ($file[$i], 'megaupload.com') AND strstr ($file[$i], '?d=')))

        {

          $main = $file[$i];

          $flag = 1;

          break;

        }



        ++$i;

      }



      $done = 0;

      if ($flag == 1)

      {

        $parse = explode ('?d=', $main);

        $parse1 = explode ('\';', $parse[1]);

        $url = 'http://www.megaupload.com/?d=' . $parse1[0];

        $done = 1;

      }

    }

 

Any help would be apriciated!

 

 

Link to comment
https://forums.phpfreaks.com/topic/175919-curl-remote-login-script/
Share on other sites

$ran=rand(1,1000);
$cookie = 'uploader'.$ran.'.txt';
$query = "login=1&redir=1&username=MY_USERNAME&password=MY_PASSWORD";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.megaupload.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$data = curl_exec($ch);
curl_close($ch);
$done = 0;

$flag = 0;

$file_loc = 'uploads/' . $info['name'];

$url = 'http://megaupload.com';

$file = @file ($url);

$count = count ($file);

$i = '0';

while ($i < $count)

{

if (strstr ($file[$i], 'megaupload.com/upload_done.php'))

{

	$main = $file[$i];

	$flag = 1;

	break;

}



++$i;

}



if ($flag == 1)

{

$parse = explode ('action="', $main);

$parse1 = explode ('" ', $parse[1]);

$posturl = $parse1[0];

$parse2 = explode ('UPLOAD_IDENTIFIER=', $posturl);

$mega_uid = $parse2[1];

$postcontent = array ();

$postcontent['file'] = '@' . $file_loc;

$postcontent['UPLOAD_IDENTIFIER'] = $mega_uid;

$postcontent['sessionid'] = $mega_uid;

$postcontent['message'] = '';

$ch = curl_init ();

curl_setopt ($ch, CURLOPT_URL, $posturl);

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);

curl_setopt ($ch, CURLOPT_POST, 1);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postcontent);

curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec ($ch);

curl_close ($ch);

$flag = 0;

$file = explode ('
', $result);

$count = count ($file);

$i = '0';

while ($i < $count)

{

	if ((strstr ($file[$i], 'megaupload.com') AND strstr ($file[$i], '?d=')))

	{

		$main = $file[$i];

		$flag = 1;

		break;

	}



	++$i;

}



$done = 0;

if ($flag == 1)

{

	$parse = explode ('?d=', $main);

	$parse1 = explode ('\';', $parse[1]);

	$url = 'http://www.megaupload.com/?d=' . $parse1[0];

	$done = 1;

}

}

This should do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.