I need help getting this script to work.

I just want to login to paypal and download my transaction history.

Here is what I have tried:

<?php

$login=urlencode("emailaddr@domain.com");
$password=urlencode("mypasswd");
$cookies="/tmp/ebay_cookies";
$agent="User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060418 Fedora/1.0.8-1.1.fc4 Firefox/1.0.8";
$header[]="text/html; charset UTF-8";

function GetCurlPage($pageSpec) {

global $agent, $cookies, $header;

$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
$tmp = curl_exec($ch);
curl_close($ch);
return $tmp;
}

function PostCurlPage($pageSpec, $data) {

global $agent, $cookies, $header;

$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$tmp = curl_exec($ch);
curl_close($ch);
return $tmp;
}

//
// Step: 1 - Hit Login Page
//
$URL = "https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-run";
$result=GetCurlPage($URL);

//
// Step: 2 - POST email address & password
//
$URL="https://www.paypal.com/cgi-bin/webscr?cmd=login-submit";
$data="close_external_flow=false&cmd=
login-submit&login_cmd=&login_params=&login_cancel_cmd=&login_email="
. $login . "&login_password=" . $password . "&submit=Log+In&form_charset=UTF-8";

$result=PostCurlPage($URL,$data);
print $result;

//
// The above two steps will get to the "Processing Login..." Page
// I can't seem to get past this page.
//
//

//
// Try posting to the "click here to reload." URL associated with "Processin Login..."
// but that take me to the login page
//
$URL="https://www.paypal.com/us/eBay/cgi-bin/webscr";
$data="cmd=_login-done&amp;$login_access";
$result=PostCurlPage($URL, $data);
print $result;

?>

    what does it do wrong?

    for what it's worth, i would bet paypal's gateway might recognize a spoofed user agent.

      I don't think it is logging me in -

      I get to the screen that says "Processing Login..." and nothing more.

      I've tried using the LiveHTTPHeaders to view all the header info being passed and thought I was sending what paypal requires to authenticate - but then again it's not working.

      If you have a paypal account, try the script.

        You see ALL the code - and you would be logging into your account. None of your info is being sent anywhere else except to paypal. There are no security issues here or is that not clear to you...

        I'm just looking for help getting this working - it's a worth while script and would be of value to the community.

          Ok - The below code if functional and will download your paypal transaction history (csv file).

          Redefine your Start Date (toward end of code).

          It ain't pretty but it works...

          <?php
          
          
          $login=urlencode("emailaddr@domain.com");
          $password=urlencode("mypasswd");
          $cookies="/tmp/paypal_cookies";
          $agent="User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060418 Fedora/1.0.8-1.1.fc4 Firefox/1.0.8";
          $header[]="text/html; charset UTF-8";
          
          
          function GetCurlPage($pageSpec) {
          
          global $agent, $cookies, $header;
          
             $ch = curl_init($pageSpec);
             curl_setopt($ch,     CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch,     CURLOPT_VERBOSE, 1);
             curl_setopt($ch,     CURLOPT_HEADER, 1);
             curl_setopt($ch,     CURLOPT_USERAGENT, $agent);
             curl_setopt($ch,     CURLOPT_HTTPHEADER, $header);
             curl_setopt($ch,     CURLOPT_FOLLOWLOCATION, 1);
             curl_setopt($ch,     CURLOPT_COOKIEJAR, $cookies);
             curl_setopt($ch,     CURLOPT_COOKIEFILE, $cookies);
             $tmp = curl_exec($ch);
             curl_close($ch);
             return $tmp;
          }
          
          
          function PostCurlPage($pageSpec, $data) {
          
             global $agent, $cookies, $header;
          
             $ch = curl_init($pageSpec);
             curl_setopt($ch,     CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch,     CURLOPT_VERBOSE, 1);
             curl_setopt($ch,     CURLOPT_HEADER, 0);
             curl_setopt($ch,     CURLOPT_REFERER, 1);
             curl_setopt($ch,     CURLOPT_USERAGENT, $agent);
             curl_setopt($ch,     CURLOPT_HTTPHEADER, $header);
             curl_setopt($ch,     CURLOPT_FOLLOWLOCATION, 1);
             curl_setopt($ch,     CURLOPT_COOKIEJAR, $cookies);
             curl_setopt($ch,     CURLOPT_COOKIEFILE, $cookies);
             curl_setopt($ch,     CURLOPT_POST, 1);
             curl_setopt($ch,     CURLOPT_POSTFIELDS, $data);
          
             $tmp = curl_exec($ch);
             curl_close($ch);
             return $tmp;
          }
          
          
          // Step: 1 - Hit Login Page
          $URL = "https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-run";
          $result=GetCurlPage($URL);
          
          // Step: 2 - POST email address & password
          $URL="https://www.paypal.com/cgi-bin/webscr?cmd=_login-submit";
          $data="close_external_flow=false&cmd=_login-submit&login_cmd=&login_params=&login_cancel_cmd=&login_email="
          . $login . "&login_password=" . $password . "&submit=Log+In&form_charset=UTF-8";
          
          $result=PostCurlPage($URL,$data);
          //print $result;
          
          
          // Posting to the "click here to reload." URL
          // You are now logged in
          $URL="https://www.paypal.com/us/eBay/cgi-bin/webscr";
          //$data="cmd=_login-done&amp;$login_access";
          $data="cmd=_login-done&amp";
          $result=PostCurlPage($URL,$data);
          //print $result;
          
          
          //
          // Download History
          //
          
          
          // Set Start Date
          $from_mo="5";
          $from_da="1";
          $from_yr="2006";
          
          
          //
          // Set End Date (current date)
          //
          $to_mo=date('m');
          $to_da=date('d');
          $to_yr=date('Y');
          
          
          //
          // Get All Activity (comma delimited enclosed in quotes)
          //
          $URL="https://history.paypal.com/us/cgi-bin/webscr";
          $data="cmd=_history-download-submit&history_cache=&type=custom_date_range&from_a=$from_mo&from_b=$from_da&from_c=$from_yr&to_a=$to_mo&to_b=$to_da&to_c=$to_yr&custom_file_type=comma_allactivity&latest_completed_file_type=&submit.x=Download+History&form_charset=UTF-8";
          $result=PostCurlPage($URL,$data,"/tmp/Download.csv");
          
          
          //
          // Write Data
          //
          $fp = fopen('/tmp/Download.csv', "w");
          fwrite($fp, $result);
          fclose ($fp);
          
          
          //
          // Logout
          //
          $URL = "https://www.paypal.com/us/cgi-bin/webscr?cmd=_logout";
          $result=GetCurlPage($URL);
          
          
          ?>
            zg0218 wrote:

            It ain't pretty

            .. and it ain't skinny, neither! :p I added the board's [ PHP ] [ /PHP ] tags (without the spaces) around your code so it's more readable and so that the page isn't stretched to the point of exploding!

            You say it does work, though? Does that resolve your problem? If so, don't forget to mark the thread resolved.

              Write a Reply...