Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1522
  • Last Modified:

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

?>
0
submissiontechnology
Asked:
submissiontechnology
  • 2
1 Solution
 
hernst42Commented:
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.
0
 
SkonenCommented:
Here it is rounded into a basic function:

function write_page(&$page, $strName, $strExt = ".txt" ) {

       if (!$fp = fopen($strFile, 'ba+'))
              return false;

       if (!fwrite($fp, $page, strlen($page))) {
              fclose($fp);
              return false;
       }

       fclose($fp);

       return true;
}


The function is binary safe, however from what you're doing it probably won't matter.

Usage:
write_page(&$page, date("dmY"), $strExt = ".txt");


Give credit to hernst42, as he posted a fine solution. I just improved on it.
0
 
SkonenCommented:
Sorry Usage is:

if (write_page($page, date("dmY"), ".txt")) {
      echo "Succeeded";
} else {
      echo "Failed";
}
0
 
JconServCommented:
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)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now