Jump to content
dsp77

Extragere informatii program afiliere whmcs

Recommended Posts

Posted

Sunt inscris la mai multe programe de afiliere care folosesc whmcs, si-mi este destul de costisitor ca timp sa le verific zilnic. De aceea am creat rapid si brut un model (clasa) pt codeigniter care preia informatiile automat (inca este in lucru).

Cerinte: CURL, PHP Simple HTML DOM Parser

Clasa functioneaza cu ultima vers de WHMCS (nu am testat toate vers.) daca nu au schimbat la design codul sursa.

<?php
class Whm_login extends CI_Model {

function __construct(){
parent::__construct();
}

function curl_login($url, $post, $fields = 3){
//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url.'dologin.php');
curl_setopt($ch,CURLOPT_FAILONERROR, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_COOKIEJAR, '/tmp/cookie.txt');
curl_setopt($ch,CURLOPT_POST, $fields);
curl_setopt($ch,CURLOPT_POSTFIELDS, $post);

//execute post
curl_exec($ch);

// print_r(curl_error($ch));
// print_r(curl_getinfo($ch));
// print_r(curl_errno($ch));

$curl_info = curl_getinfo($ch);

//close connection
curl_close($ch);

if($curl_info['redirect_url'] == $url.'clientarea.php?incorrect=true'){
echo 'invalid user/pass for: '.$url;
return false;
} else {
//access affiliate page
$output = $this->curl_aff($url);

return $output;
}
}

function curl_aff($url){
//open connection
$ch = curl_init ();

//get affiliate page with cookie set
curl_setopt($ch,CURLOPT_URL, $url.'affiliates.php');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_FAILONERROR, true);
curl_setopt($ch,CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute curl
$output = curl_exec($ch);

// print_r(curl_error($ch));
// print_r(curl_getinfo($ch));
// print_r(curl_errno($ch));

//close connection
curl_close($ch);
return $output;
}

function login($vars){
//url-ify the data for the POST
foreach($vars['fields'] as $key=>$value){
@$fields_string .= $key.'='.$value.'&';
}
$res = rtrim($fields_string, '&');

//login, get cookie, access aff page
$output = $this->curl_login($vars['url'], $res);

//retrieve affiliate info
if($output){
$this->html = str_get_html($output);
foreach($this->html->find('.bigfield') as $v){
$data[] = $v->value;
}
foreach($this->html->find('.stat') as $v){
$data[] = $v->innertext;
}
foreach($this->html->find('table.halfwidthcontainer tbody tr') as $v){
$data[] = trim($v->plaintext);
}

//clear
$this->html->clear();
unset($this->html);

$data['source'] = $vars['source'];
$data['reflink'] = $data[0];
$data['visitors'] = $data[1];
$data['signups'] = $data[2];
$data['conversion'] = $data[3];
$data['maturation'] = $data[4];
$data['balance'] = $data[5];
$data['withdrawn'] = $data[6];
unset($data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6]);
return ($data);
} else {
return false;
}
}
}

Cum se foloseste:

		$vars['source']					= 'Nodedeploy';
$vars['url'] = 'https://nodedeploy.com/clients/';
$vars['fields']['token'] = urlencode('c12fc6614d723df9e63ecca3a639eb9d58e2370e');
$vars['fields']['username'] = urlencode('xxxxxxxxxxxx@gmail.com');
$vars['fields']['password'] = urlencode('xxxxxxxxxxxxxxxx');

$data = $this->Whm_login->login($vars);

Daca aveti sugestii/imbunatatiri/idei le voi analiza si implementa dupa caz.

P.S. Sa nu va aud ca nu stiti sa o folositi pt ca este in codeigniter, deoarece este usor de transformat intr-o clasa de sine statatoare (folositi-va cel mai accesibil si util gadget numit creier).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...