Grab DirectTrack & Advaliant Subid's and update in Prosper202

Status
Not open for further replies.

Bandit

Get Money Get Paid
Apr 29, 2007
59
3
0
Ohio
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:

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);
    }
}
?>
Second file, dt.class.php:

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();
    }

}
?>
--POST CONTINUED BELOW--
 
  • Like
Reactions: erect


Post Continued...

Third, advaliant.class.php:

Code:
<?php
/*
 * AUTHOR: Bandit
 * DATE: 9/16/08
 * VERSION: 0.1
 *
 * This code logs into advaliant and grabs subid stats FOR THE CURRENT DAY
 */
include('curl.class.php');

class advaliant {

  var $viewstate; //big ass variable of a whole buncha mumbo jumbo.

  function get_viewstate_var() {
    $curl = new Curl();
    $login_page = $curl->get("https://portal.advaliant.com/login.aspx");
    $regex = '/<input type="hidden" name="__VIEWSTATE" value="(.*)"/';
    preg_match_all($regex, $login_page, $matches);
    //var_dump($matches);
    $this->viewstate = $matches[1][0];
  }
  function advaliant_login($username, $password) {
    $curl = new Curl();
    $this->get_viewstate_var();
    $submit_url = "https://portal.advaliant.com/login.aspx";
    $referer = "https://portal.advaliant.com/login.aspx";
   
    $post_vars['__VIEWSTATE'] = urlencode($this->viewstate);
    $post_vars['TxtLoginNamenew'] = urlencode($username);
    $post_vars['TxtPasswdnew'] = urlencode($password);
    $post_vars['btnLogin.x'] = "87";
    $post_vars['btnLogin.y'] = "9";
   
   
    $post_string = $this->make_post_string($post_vars);
    if ($post = $curl->postForm($submit_url, $post_string, $referer)) {
     //var_dump($post);
     //uncomment above line to troubleshoot....login most likely successful :-D
    }
  }
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 return_converted_subids() { //returns array of converted subid FOR THE DAY
    $curl = new Curl();
    $html = $curl->get("https://portal.advaliant.com/Reports/AdStatsAffiliate3.aspx");
    //var_dump($html);
    $regex = '/<td align="Left"><font face="Verdana" color="Black" size="2">.*<\/font><\/td><td align="Left" valign="Middle"><font face="Verdana" color="Black" size="2">.*<\/font><\/td><td align="Right" valign="Middle"><font face="Verdana" color="Black" size="2">(.*)<\/font><\/td><td align="Right" valign="Middle"><font face="Verdana" color="Black" size="2">.*<\/font><\/td><td align="Left"><font face="Verdana" color="Black" size="2">(.*)<\/font><\/td>/';
    preg_match_all($regex, $html, $matches, PREG_PATTERN_ORDER);
    //var_dump($matches);
    $ad_leads = $matches[1];
    $all_subids = $matches[2];
    $num_elements = sizeof($all_subids) - 1;
   
    $i = 0;
    while($i <= $num_elements) {
      if ($ad_leads[$i] > 0) {
        //echo "Converted Subid: ".$all_subids[$i]."<br />";
        if ($all_subids[$i] > 0) {
          $converted_subids[] = $all_subids[$i];
        }
      }
      $i++;
    }
    //var_dump($converted_subids);
    //echo $converted_subids[2];
    return $converted_subids;
  }
}
?>

And last but not least, the prosper202 class :-)

Code:
<?php
/*
 * FILE: prosper202.class.php
 * AUTHOR: Bandit
 * DATE: 9/16/08
 * VERSION: 0.1
 *
 * This code logs into prosper202 and updates the specified subid's into conversions.
 */
include('curl.class.php');

class prosper202 {

  var $domain; //setup var
  var $token; //variable token needed to post to login.

  function get_token_var() {
    $curl = new Curl();
    $this->destroy_cookies();
    $login_page = $curl->get($this->domain."/202-login.php");
    //var_dump($login_page);
    $regex = '/<input type="hidden" name="token" value="(.*)"\/>/';
    preg_match_all($regex, $login_page, $matches);
    //var_dump($matches);
    $this->token = $matches[1][0];
  }
  function p202_login($username, $password) {
    $curl = new Curl();
    $this->get_token_var();
    $submit_url = $this->domain."/202-login.php";
    $referer = $this->domain."/202-login.php";
   
    $post_vars['token'] = urlencode($this->token);
    $post_vars['user_name'] = urlencode($username);
    $post_vars['user_pass'] = urlencode($password);
   
    $post_string = $this->make_post_string($post_vars);
    if ($post = $curl->postForm($submit_url, $post_string, $referer)) {
      //var_dump($post);
     //uncomment above line to troubleshoot....login most likely successful :-D
    }
  }
  function update_converted_subids($array) { //updates converted subids.
    $curl = new Curl();
    $submit_url = $this->domain."/tracking202/update/subids.php";
    $referer = $this->domain."/tracking202/update/subids.php";
   
    $post_string = "subids=".implode("\r\n", $array);
    //print urlencode($post_string); //%0A%0D is a linefeed...aka \r\n (newline, carriage return)
    if ($post = $curl->postForm($submit_url, $post_string, $referer)) {
      //var_dump($post);
     //uncomment above line to troubleshoot....update most likely successful :-D
     echo "\nUpdate Of Subid's Successful :-)\n\n";
    }
  }
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 prosper202($domain) { //This function is executed on class initiation - $domain should be http://example.com - NO ENDING SLASH
   if (!stristr($domain, "http://")) {
     $domain = "http://".$domain;
   }
   $this->domain = $domain;
 }

}
?>

Now that you have those four class files, put them all in the same directory. I put them in a folder called includes. Oh yeah, forgot to mention. Make sure the directory is writable because the cURL class creates a file called cookies.txt to store cookie information.

Okay, now for exectuting it all. The following will be the file you will want to actually cron. I have documented the code, so follow the instructions:

Code:
<?php
/*
 * AUTHOR: Bandit
 * DATE: 9/16/08
 * VERSION: 0.1
 *
 * This code glues everything together and actually updates the subid's inside of prosper202. This is the file
 * you will want to put in your cron job.
 */

include('includes/curl.class.php');
include('includes/advaliant.class.php');
include('includes/dt.class.php');
include('includes/prosper202.class.php');

//edit the next line with your p202 domain:
$p202 = new prosper202("http://YOUR-PROSPER202-DOMAIN.com");
$advaliant = new advaliant();
//edit the next line with your advaliant username and password:
$advaliant->advaliant_login("ADVAL-USERNAME", "PASSWORD");
$conversions = $advaliant->return_converted_subids();

//edit the following line for your directtrack info DT-DOMAIN should be like:
//ads4dough.com   no http://, no trailing /
$dt = new DT("DTLOGIN@EMAIL.COM", "DTPASSWORD", "DT-DOMAIN");
//now, let's make it get last 3 days subid's, just in case some leads came in late
//feel free to edit the following code. All it does it sets the start and end date to the last three days, relatively.
$now = time();
$three_days = (60 * 60 * 24 * 3);
$three_days_ts = $now - $three_days;
$start_day = date("j", $three_days_ts);
$start_month = date("n", $three_days_ts);
$start_year = date("Y", $three_days_ts);
$current_day = date("j");
$current_month = date("n");
$current_year = date("Y");
$dt->set_start_date($start_month, $start_day, $start_year);
$dt->set_end_date($current_month, $current_day, $current_year);
$converted_subids = $dt->get_subids();

//edit the following line for your p202 login info:
$p202->p202_login("P202USER", "P202PASS");
$p202->update_converted_subids($conversions);
$p202->update_converted_subids($converted_subids);

/*
 * you're done! If you wanted to do another DT network, you can just unset($dt); and then copy the
 * DT portion of the code, with a different DT network domain. Enjoy!
 *
 * --Bandit
 */

?>

Yeah, I know it's hard to setup, but once you do, you just sit and leave it. Sorry, I code everything in my own little custom environment, so it's not really suited to be easy to install, but I figured I'd share anyways.

So, in the above file, just name is p202.php and then set a cron job for it how ever often you want your subid's updated. Then, throw all the above four class files into a folder called 'includes' and you should be ready to go. Any questions or comment, feel free to post here or contact me any way you wish through my profile page here on wickedfire.

Also, let me say if any of you would like to partner up with me on any money-making projects, feel free to contact me. I can code pretty much anything, and am not just limited to PHP. If I don't know how to do something, I'll find out how and do it. I'm good with computers all-around, including server management, unix, linux, etc. I'm always looking to expand and branch out and work with new people. Just thought I'd throw that in there ;)

Anyways, again I apologize that it's not that easy to install, and for the messy code. But it works! :) Enjoy and I hope this helps everyone better manage their campaigns!

-Bandit
 
HMM, for some reason I can't edit my posts anymore.

Everyone, please comment out or delete line 19 out of the prosper202.class.php file

the line is:

Code:
$this->destroy_cookies();

Sorry, that was from some old code.
 
Thanks

Troubleshooting tips - im using php5
Cannot redeclare class Curl, put // in front of include('curl.class.php'); for all the .class files, fixed it

Fatal error: Call to a member function set_start_date()
Just make sure you use at least one DT login, I just // the $dt line but you can't do that

Fatal error: Call to undefined method prosper202::destroy_cookies()
just uncomment line 19 ***Removed comppletely from script now***

Then I got error Warning: implode() [function.implode]: Invalid arguments passed
Meaning no subids are getting passed

Go make a cookies.txt file and upload it in the same directory as index.php.. CHMOD 777 IT and it should work!
 
GAH, sorry guys one more thing.

Create a blank cookies.txt file in the directory where the file you're executing is at. You don't need one in the includes directory where the class files are. Sorry for the triple post :(
 
Great coding and share for everyone bandit. I don't use p202 so I personally can't take advantage of it ... but everyone that does owes you a big ass debt of gratitude.
 
This is pretty sweet, if I get back into trying adwords and using prosper202 I will definitely use this. You rock.
 
Thank you everyone for your kind words, I really appreciate it and am glad the code can help some of you out.

@tom_e_rock: Donation is most definitely not necessary, I enjoying helping people. The way I see it, you reap what you sow. Thank you very much for the thought though :-)

To everyone else, if you have any problems, feel free to post here. I didn't exactly make the code super easy to install.

Thanks

-Bandit
 
  • Like
Reactions: ChrisS
Here's a class to work with hydranetwork.com

Thanks Bandit.
I hope someone finds this additional class useful.

Code:
<?php
/*
 * AUTHOR: ntro
 * DATE: 11/19/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.
 * Credit goes to Bandit for most of the code.  I just tweaked it to work with Hydra
 *
 * This code logs into hydranetwork.com and grabs subid stats for the specified date range.
 */
#include('curl.class.php');

class Hydra {
    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 Hydra_login() {
        $curl = new Curl();
        $referer = "https://www.hydranetwork.com/";
        $submit_url = "https://network.hydranetwork.com/process_login.php";
        $post_vars['email_address'] = urlencode($this->username);
        $post_vars['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 = "http://network.hydranetwork.com/download_report_stats.php?group_by_sid=on&group_by_sidaction=on&start_xdate=".$this->start_year.'-'.$this->start_month.'-'.$this->start_day."&end_xdate=".$this->end_year.'-'.$this->end_month.'-'.$this->end_day."&sortcol=&sortdir=";
        $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[3]);
                $click_id = str_ireplace('"', "", $click_id);
                $click_id = trim($click_id);
                if (is_numeric($click_id)) {
                    #echo "click id: (".$click_id.")\n";
                    $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 Hydra($username, $password) { //this function is exectuted upon class initiation.
        $this->username = $username;
        $this->password = $password;
        $this->Hydra_login();
    }

}
?>
 
Awesome, thanks lteague! Good to see other people jumping in and contributing as well. I think eventually I'm gonna get around to making a neverblue one, when I get some free time :)
 
Good shit, bud. Turning down donations and leaving it to karma is the icing on the cake. +rep
 
Status
Not open for further replies.