Link to home
Start Free TrialLog in
Avatar of submissiontechnology
submissiontechnology

asked on

copy the content

I'm using this curl script to login and display a page that i want but i need to copy the content of the display page to file/database how can I do this?






<?php
// ---- LOGIN ---

$referer = "http://www.tradedoubler.com"; // site main url
$url = "http://www.tradedoubler.com/pan/login"; // url of login form post too

$ch = curl_init();

$postvars = "j_username=******&j_password=******"; // list the form variables

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);  // HTTPS
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MUTE, 1); // do not identify client as Curl
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); // fake to be Internet Explorer 6.0
curl_setopt($ch, CURLOPT_POST, 1); // change if GET is used in the form
curl_setopt($ch, CURLOPT_HEADER, 1); // return HTTP header
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); // send the POST variables separated with &
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");  // autosaves cookies in tmp file

$page = curl_exec($ch); // the returned page
$error = curl_error($ch);

// echo $error."\r\n"; // for debuging purposes

curl_close($ch);

// --- GET PAGE --- (while logged in)

$url = "http://www.tradedoubler.com/pan/reports/Epi?cache=invalidate&navProgramId=&navOrganizationId=&reportSelection=true&program_id=0&affiliate_id=0&period=custom_period&reportType=csv&startDay=11&startMonth=10&startYear=2004&endDay=11&endMonth=10&endYear=2004&showDeleted=false&nrOfCols=0"; // url of the page you want to go to
$referer = "http://www.tradedoubler.com/pan/login";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // HTTPS
curl_setopt($ch, CURLOPT_REFERER, $referer); // use the loginpage as referer this time
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName"); // load cookies from tmp file



$page = curl_exec($ch);
$error = curl_error($ch);

curl_close($ch);

//echo $error."\r\n"; // for debuging purposes

echo $page; // the returned page

?>
Avatar of hernst42
hernst42
Flag of Germany image

As you have your page-content in the variable $page you can write that content to a file like this:

$fn = date("Ymd") . '.txt';
$fp = fopen($fn, 'a+');
fputs($fp, $page);
fclose($fp);

Write all page content retrieved for that day to one file. You make also the filename more unique or identifyable.

If you want to store the content in a database use a text-field to store that content. The code depends on the database you use.
ASKER CERTIFIED SOLUTION
Avatar of Skonen
Skonen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Skonen
Skonen

Sorry Usage is:

if (write_page($page, date("dmY"), ".txt")) {
      echo "Succeeded";
} else {
      echo "Failed";
}
at the top place ob_start(); //starts output buffering

then after your last line of output place the dump variable
$display_data = ob_get_contents(); // get buffer contents
ob_end_flush(); //send output

and then use the function posted above to write your data.

(Note: output buffering does cause some overhead, nothing to be worried about though)