0

I want to write a php script that:

A. logs into a web site B. navigates to specific page (which is a csv file download) C. store the results in a string.

Something like:

$site->connect("dashboard.site.com");
$site->post_vars(array("username"=>"mike","password"=>"2345");
$csv_file = $site->download("dashboard.site.com/file.csv");

I've read about the snoopy class, but documentation seems to not exist so I can't be sure if this is something it can do.

danjfoley
  • 778
  • 1
  • 8
  • 20

1 Answers1

0

I figured out how to use Curl to do it. My own login and password and merchant group of course are hidden in this code. But here's how to do it: I hope this helps anyone in the same situation.

$cookie_jar = tempnam('/tmp','cookie');

// log in
$c = curl_init('https://dashboard.powerreviews.com/dashboard/login');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, false);
$page = curl_exec($c);
curl_close($c);

$post_fields = array("j_username" => "USERNAME", "j_password" => "PASSWORD", "command"=>"Login");
$post_data = http_build_query($post_fields);

$c = curl_init('https://dashboard.powerreviews.com/process_login');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $post_data);
$page = curl_exec($c);
curl_close($c);

// switch to Reviews Account
$c = curl_init('https://dashboard.powerreviews.com/programs/epc?accessMerchantGroup=xxxxx');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$csv_file = curl_exec($c);
curl_close($c);


// download RA unsubscribes
$c = curl_init('https://dashboard.powerreviews.com/dashboard/unsubscribes.csv');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$csv_file = curl_exec($c);
curl_close($c);
echo $csv_file;
danjfoley
  • 778
  • 1
  • 8
  • 20