2

I'm trying to login to megaupload.com using cURL and PHP. What I want to do is login so I have premium access, and then download a file. This the code for my login method:

public function login()
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.megaupload.com/?c=login");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "username={$this->username}&password={$this->password}&login=1");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $store = curl_exec($ch);
    curl_close ($ch);
}

And this is my index.php:

<?php

include_once("plugins/megaupload.class.php");

$megaupload = new Megaupload("username", "password");

$megaupload->login();

?>

But nothing seems to happen. When I run the script, cookie.txt isn't saved anywhere. I got the POST values from Firebug:

login=1&password=password&redir=1&username=username

This is what's being sent through the form when I log in using their site. And yeah, the username and password is correct.

Thanks for any help!

EDIT: Okay, it seems it is actually logging in as I can access my account page, which I wouldn't be able to unless I'm logged in. But that still doesn't solve where the cookie.txt file is being saved...

Josh
  • 1,361
  • 5
  • 22
  • 33

3 Answers3

1

You need to make sure the directory where you're trying to store the cookie is world-writable.

Also, you should use an absolute path (setup a separate folder outside of your webroot, if you're able), and ensure proper permissions.

You should also set the CURLOPT_COOKIEFILE option:

url_setopt($ch, CURLOPT_COOKIEFILE, ABS_PATH_TO_COOKIE_TXT);
gnxtech3
  • 782
  • 3
  • 7
0

It seems CURLOPT_COOKIEJAR option have some problems with relative urls. Try setting an absolute path:

curl_setopt($ch, CURLOPT_COOKIEJAR, realpath("cookie.txt"));

spawnedc
  • 476
  • 5
  • 9
0

It might be this error:

http://www.renownedmedia.com/blog/php-curl-cookies-not-saving-on-windows/

Thomas Hunter II
  • 5,081
  • 7
  • 35
  • 54