At the digital point forums today, someone asked if it there was a email report that could be sent from CJ. I’ve looked for this in the past, but have not had any luck finding this feature, and thought it might be cool to throw something together that sort of does this.
My idea was simple, to create a PHP application that would use cURL to login and return me the quick stats results. After retrieving the stats, it would email me the results. I used one library called LIB_parse.php which makes it extremely handy to parse through HTML code to drill down to the specific section you’re looking for. To get this to email, you’ll need to run this is crontab. Possible as a PHP-CLI (command line script) or use lynx/wget to hit a web page to execute the code.
Below is the code to get this to work:
include("lib/LIB_parse.php");
$uname = "account@yourdomain.com";
$password = "CJPassword";
$loginURL = "https://members.cj.com/member/foundation/memberlogin.do"; // keep it secure with SSL
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$POSTFIELDS = ‘uname=’.$uname.‘&nextpage=&pw=’.$password;
$emailAddy = "account@yourdomain.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$loginURL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if(!$result = curl_exec ($ch)){
echo "Unable to access site";
}else{
curl_close ($ch);
$zone_array = parse_array(
$result,
"<!–Quickstats table—>",
"<!–trend graph table—>",
INCL
);
$quickStats = $zone_array[0];
//echo $quickStats;
$to = $emailAddy;
$subject = "CJ Quick Stat Report";
$message = $quickStats;
$headers = "MIME-Version: 1.0".chr(10);
$headers .= "From:".$emailAddy.chr(10);
$headers .= "Content-type: text/html; charset=iso-8859-1".chr(10);
mail($to, $subject, $message, $headers);
}
?>
You can download the file(s) here:
stat_lookup.php
LIB_parse.php
Disclaimer! I don’t know if this is against any CJ terms.. so use at your own risk.
Related posts:
I down it now, thank you for share it, i will try it .