Jump to content

Need help authenticating with curl and PHP


Dustin013

Recommended Posts

Basically I am trying to authenticate a session to see if a file exist on a hosting provider, and what the download link would be (www.megashares.com). I have a php script which is parsing the data fine if I save the html file to my local machine. Without logging into the site the script obviously can't parse the correct page... so here is what I have at the moment based off a tutorial I found at : http://drupal.org/node/89710.

<?php
    $crl = curl_init();
    $url2 = "http://www.megashares.com/index.php";
    curl_setopt($crl, CURLOPT_URL, $url2);
    curl_setopt($crl, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($crl, CURLOPT_COOKIEJAR, "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(
     		 "lc[email]"=>"[email protected]",
     		 "lc[pin]"=>"12345678",
     		 "lc[signin]"=>"Sign-In",
   		 );
// tell curl we're going to send $postdata as the POST data
    
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
    $result=curl_exec($crl);
    $headers = curl_getinfo($crl);
    if ($headers['url'] == $url2) {
        die("Cannot login to MegaShares.com!");
    }

?>

 

It simply isn't working... any suggestions or other methods?

I brought up PHP info and Curl is enabled...

 

curl

cURL support enabled

cURL Information libcurl/7.16.0 OpenSSL/0.9.8e zlib/1.2.3

 

Here is the code

<?php
    $crl = curl_init();
    $url2 = "http://d01.megashares.com/index.php";
    curl_setopt($crl, CURLOPT_URL, $url2);
    curl_setopt($crl, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($crl, CURLOPT_COOKIEJAR, "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(
     		 "lc[email]"=>"xxxxxxxx",
     		 "lc[pin]"=>"xxxxxxxx",
     		 "lc[signin]"=>"Sign-In",
		 "lc[login]"=>"lc_login",
   		 );
// tell curl we're going to send $postdata as the POST data
  
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
    $result=curl_exec($crl);
  
if (curl_errno($result) != 0) //CURL error
{
echo "<hr><br>\n";
echo 'Errors: '.curl_errno($result).' '.curl_error($result).'<BR><BR>';
echo "<hr><br>\n";

}
    $headers = curl_getinfo($crl);
    if ($headers['url'] == $url2) {
        die("Cannot login to MegaShares.com!");
    }

?>

 

I keep getting this error:

 

Warning: curl_errno(): supplied argument is not a valid cURL handle resource in C:\Program Files\VertrigoServ\www\dailyddl\include\megasharelogin.php on line 22

Cannot login to MegaShares.com!

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.