开发者

Logging into Megaupload with cURL and PHP

开发者 https://www.devze.com 2023-03-08 02:16 出处:网络
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:

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 开发者_StackOverflowindex.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...


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);


It might be this error:

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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消