Hey all,
It has occured to me that I'm not really an active member here and I haven't really given back to the community, though I read here pretty much every day.
With that being said, let me first say that credit goes to Jason Akatiff aka Smaxor for the DirectTrack class concept. It was his idea to login and grab the data, and I even used a couple modified functions from his original code, located at oooff.com
So, I created an advaliant class to login to advaliant and retrieve converted subids, and another directtrack class to login to any directtrack network and grab any converted subids, and finally a prosper202 class to login to prosper202 and update the converted subid's.
The code is cURL based, so you don't need to insert any of your database details. There are about four files you will need. Sorry, I always organize my code into separate classes.
If I were you, I'd set a cron job to run the main file every hour or so. Sometimes pixel's misfire or don't fire and stuff like that. I will show an example below.
Sorry, for the advaliant class, it only gets subid data for the current date. Truth be told I was too lazy to implement date range. Shouldn't matter, I just put it on a cron anyway..
Please don't bitch and moan at my code. Yes, it's messy. But it works. Remember, this is free for everyone.
So, without further ado, behold the mighty CODE tags:
First, the cURL class that I use for pretty much all my programming:
Second file, dt.class.php:
--POST CONTINUED BELOW--
It has occured to me that I'm not really an active member here and I haven't really given back to the community, though I read here pretty much every day.
With that being said, let me first say that credit goes to Jason Akatiff aka Smaxor for the DirectTrack class concept. It was his idea to login and grab the data, and I even used a couple modified functions from his original code, located at oooff.com
So, I created an advaliant class to login to advaliant and retrieve converted subids, and another directtrack class to login to any directtrack network and grab any converted subids, and finally a prosper202 class to login to prosper202 and update the converted subid's.
The code is cURL based, so you don't need to insert any of your database details. There are about four files you will need. Sorry, I always organize my code into separate classes.
If I were you, I'd set a cron job to run the main file every hour or so. Sometimes pixel's misfire or don't fire and stuff like that. I will show an example below.
Sorry, for the advaliant class, it only gets subid data for the current date. Truth be told I was too lazy to implement date range. Shouldn't matter, I just put it on a cron anyway..
Please don't bitch and moan at my code. Yes, it's messy. But it works. Remember, this is free for everyone.
So, without further ado, behold the mighty CODE tags:
First, the cURL class that I use for pretty much all my programming:
Code:
<?php
class Curl
{
function setup()
{
$cookieJar = 'cookies.txt';
curl_setopt($this->curl,CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt($this->curl,CURLOPT_COOKIEFILE, $cookieJar);
//curl_setopt($this->curl,CURLOPT_AUTOREFERER, true);
curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curl,CURLOPT_RETURNTRANSFER, true);
//curl_setopt($this->curl, CURLOPT_HTTPPROXYTUNNEL, '193.136.227.163:3124');
curl_setopt($this->curl, CURLOPT_HEADER, 1);
//curl_setopt($this->curl, CURLOPT_PROXY, '193.136.227.163:3124');
// curl_setopt($this->curl, CURLOPT_HTTPTUNNELPROXY,'193.136.227.163:3124');
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, '20');
curl_setopt($this->curl,CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.14');
//SSL ----------------------------------------------------------------------------
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 2);
}
function get($url)
{
$this->curl = curl_init($url);
$this->setup();
return $this->request();
}
function getAll($reg,$str)
{
preg_match_all($reg,$str,$matches);
return $matches[1];
}
function postForm($url, $fields, $referer='')
{
$timeout = 15;
$this->curl = curl_init($url);
$this->setup();
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_REFERER, $referer);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields);
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Expect:'));
return $this->request();
}
function getInfo($info)
{
$info = ($info == 'lasturl') ? curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL) : curl_getinfo($this->curl, $info);
$info = ($info == 'http_code') ? curl_getinfo($this->curl, CURLINFO_HTTP_CODE) : curl_getinfo($this->curl, $info);
return $info;
}
function request()
{
return curl_exec($this->curl);
}
}
?>
Code:
<?php
/*
* AUTHOR: Bandit
* DATE: 11/04/08
* VERSION: 0.1
* Credit goes to Jason Akatiff AKA Smaxor for the original concept.
* Credit goes to Jason Akatiff AKA Smaxor for small portions of this code.
*
* This code logs into (pretty much) any directtrack system and grabs subid stats for the specified date range.
*/
include('curl.class.php');
class DT {
var $domain;
var $username;
var $password;
var $start_month;
var $start_day;
var $start_year;
var $end_month;
var $end_day;
var $end_year;
var $filename;
function DT_login() {
$curl = new Curl();
$submit_url = "https://affiliates.".$this->domain."/";
$referer = $submit_url;
$post_vars['DL_AUTH_USERNAME'] = urlencode($this->username);
$post_vars['DL_AUTH_PASSWORD'] = urlencode($this->password);
$post_string = $this->make_post_string($post_vars);
if ($post = $curl->postForm($submit_url, $post_string, $referer)) {
//login most likely successful.
$html = $post;
if (strpos($html, "not logged into")) {
die("Login failed, probably wrong username / password combo");
}
if (strpos($html, "you entered is invalid")) {
die("Login failed, wrong username / password combo");
}
else {
//99% chance login was successful!
//var_dump($html); //uncomment for trouble shooting <----
}
}
else {
die("Login cURL POST failed.");
}
}
function get_advanced_stats() {
$curl = new Curl();
$url = "https://affiliates.".$this->domain."/partners/monthly_affiliate_stats.html?program_id=0&affiliate_stats_start_month=".$this->start_month."&affiliate_stats_start_day=".$this->start_day."&affiliate_stats_start_year=".$this->start_year."&affiliate_stats_end_month=".$this->end_month."&affiliate_stats_end_day=".$this->end_day."&affiliate_stats_end_year=".$this->end_year."&breakdown=cumulative&get_lead_info=Download+Optional+Info";
$csv_raw = $curl->get($url);
if (!$csv_raw || $csv_raw == "" || $csv_raw == NULL) {
die("Error fetching .csv advanced stats file. Maybe it's blank?");
}
unset($curl);
return $csv_raw;
//$csv_array = $this->csv2array($csv_raw);
//return $csv_array;
}
function set_start_date($month, $day, $year) { //make sure days and months before '10' do NOT have a preceding 0
$this->start_month = $month;
$this->start_day = $day;
$this->start_year = $year;
}
function set_end_date($month, $day, $year) { //make sure days and months before '10' do NOT have a preceding 0
$this->end_month = $month;
$this->end_day = $day;
$this->end_year = $year;
}
function make_post_string($array) { //takes assoc array and makes it into a post string :-)
foreach($array as $f => $v)
$array .= $f . '=' . $v . '&';
$array = rtrim($array, '&');
$array = str_ireplace("array", "", $array);
$post_string = $array;
return $post_string;
}
function csv2array($raw_csv){
$return = array();
//lines to array
$stats = explode("\n",trim($raw_csv));
foreach($stats as $line){
//fields to array
$fields = explode(",",trim($line));
$record = array();
foreach($fields as $field) {
$record[] = trim($field);
}
$return[] = $record;
}
return $return;
}
function parse_subids($csv_array) {
$count = 0;
foreach($csv_array as $row) {
if($count != 0) {
$click_id = trim($row[2]);
if ($click_id != "" && $click_id != "Info" && $click_id != NULL && $click_id != "NULL") {
$click_id = str_ireplace('"', "", $click_id);
$click_id = trim($click_id);
//echo "click id: ".$click_id."<br /><br />";
$subids[] = $click_id;
}
}
$count ++;
}
return $subids;
}
function get_subids() {
$csv_raw = $this->get_advanced_stats();
$csv_array = $this->csv2array($csv_raw);
$subids = $this->parse_subids($csv_array);
return $subids;
}
function DT($username, $password, $domain) { //this function is exectuted upon class initiation.
$this->domain = $domain;
$this->username = $username;
$this->password = $password;
$this->DT_login();
}
}
?>